使用jsf为每种类型的用户提供菜单

时间:2022-05-15 20:03:14

i'm trying to include a menu in a template that's used in my web pages, the thing is that my menu changes according to wich type of users is connected. oh and i'm using jsf. so page->template->menu in the first page login.xhtml a button takes the user to the bean:

我试图在我的网页中使用的模板中包含一个菜单,问题是我的菜单根据用户类型的连接而变化。哦,我正在使用jsf。所以第一页中的page-> template-> menu login.xhtml一个按钮将用户带到bean:

<p:commandButton id="logins"  value="login"  action="#{UtilisateurBean.connection_role}"  update="growl"/>

in the utilisateurBean the methode connection_role looks like this:

在utilisateurBean中,methode connection_role看起来像这样:

public String connection_role() {
    Utilisateur authentifi = resp.seConnecter_role(login, password, typeRole);
    FacesMessage msg;
    FacesContext myFacesContext;

    if ("_".equals(authentifi.getLogin())) {
        msg = new FacesMessage("Compte incorrect", "Login password incorrect");
        msg.setSeverity(FacesMessage.SEVERITY_INFO);

        myFacesContext = FacesContext.getCurrentInstance();
        myFacesContext.addMessage(null, msg);

        return null;
    } else if (authentifi != null) {
        Utilisateur user = resp.findById(idutilisateur);
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if (typeRole.equals("Administrateur")) {
            cleanForm();
            setMenu("menuAdministrateur.html");
            session.setAttribute("user", user);
            return "listItem.xhtml";
        } else if (typeRole.equals("Administrateur Audit")) {
            cleanForm();
            setMenu("menuAdministrateurAudit.html");
            session.setAttribute("user", user);
            return "Administrateur_Audit";
        } else if (typeRole.equals("Planificateur")) {
            cleanForm();
            setMenu("menuPlanificateur.html");
            session.setAttribute("user", user);
            return "Planificateur";
        } else {
            cleanForm();
            setMenu("menuAuditeur.html");
            session.setAttribute("user", user);
            return "Auditeur";
        }

    }

    return null;
}

in my template i'v put :

在我的模板中我放了:

now when i click on the login button the page thasn't go anywhere, the user is connected i'v cheked that with some printlns but no calling any other page.

现在,当我点击登录按钮页面没有去任何地方,用户已连接我用一些printlns cheked但没有调用任何其他页面。

Ps: if i replace <ui:insert name="#{UtilisateurBean.menu}" ></ui:insert> with <ui:insert name="menuAuditeur.xhtml" ></ui:insert> it works just fine and the new page shows up

Ps:如果我用 替换 它可以正常工作新页面出现了

1 个解决方案

#1


0  

If you wrap the <ui:insert... with <h:panelGroup id="myPanel"... and in your <p:commandButton add the myPanel id to the list of elements to update? Like <p:commandButton update="growl, myPanel" .... ?

如果你用

In case a form with id surrounds the <ui:insert you should do something like <p:commandButton update="growl, form1Id:myPanel

如果带有id的表单围绕 ,您应该执行类似

?

#1


0  

If you wrap the <ui:insert... with <h:panelGroup id="myPanel"... and in your <p:commandButton add the myPanel id to the list of elements to update? Like <p:commandButton update="growl, myPanel" .... ?

如果你用

In case a form with id surrounds the <ui:insert you should do something like <p:commandButton update="growl, form1Id:myPanel

如果带有id的表单围绕 ,您应该执行类似

?