4

操作方法在我的<p:menuitem>. 我想activeIndex通过<p:menuitem>.

下面的代码是我的页面中使用的模板页面上的代码:

<h:form>
    <p:tabMenu activeIndex="#{loginBean.activeindex}">  
        <p:menuitem value="Home" url="Menu.jsf" icon="ui-icon-star" />
        <p:menuitem value="Fabricants" url="/pagess/pagesFabricant/Fabricant.jsf" icon="ui-icon-wrench"   action="#{loginBean.Dirige(1)}" /> 
        <p:menuitem value="Composants" url="/pagess/pagesComposant/Composant.jsf" icon="ui-icon-search"  action="#{loginBean.Dirige(2)}"/> 
        <p:menuitem value="Dossier d'equivalence" url="DEQ.jsf" icon="ui-icon-document" action="#{loginBean.Dirige(3)}"/> 
    </p:tabMenu> 
</h:form>

这是我的豆子:

public class LoginBean {

    private int activeindex;

    public int getActiveindex() {
    return activeindex;
    }

    public void setActiveindex(int activeindex) {
        this.activeindex = activeindex;
    }  

   public void Dirige(int a){
       setActiveindex(a);
   }
}

当我单击任何菜单项时,不会调用操作方法。我做了一些调试以确保不调用该方法。或者,该方法正在使用<p:commandButton>.


这是模板

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:p="http://primefaces.org/ui">

    <h:head>
<ui:insert name="title">Title</ui:insert></title>
    </h:head>
    <h:body>

    <h:form>
    <p:tabMenu activeIndex="#{loginBean.activeindex}">  
        <p:menuitem value="Home" url="Menu.jsf" icon="ui-icon-star" />
        <p:menuitem value="Fabricants" url="/pagess/pagesFabricant/Fabricant.jsf" icon="ui-icon-wrench"   action="#{loginBean.Dirige(1)}" /> 
        <p:menuitem value="Composants" url="/pagess/pagesComposant/Composant.jsf" icon="ui-icon-search"  action="#{loginBean.Dirige(2)}"/> 
        <p:menuitem value="Dossier d'equivalence" url="DEQ.jsf" icon="ui-icon-document" action="#{loginBean.Dirige(3)}"/> 
    </p:tabMenu> 
    </h:form>
    <p/>
    <table border="5" align="center">
      <tr><th class="title">
        Bienvenue #{loginBean.username} dans Notre application Ipertool
      </th></tr>
    </table><p/>


    <ui:insert name="body">Body</ui:insert>

    <p:separator id="separator"/> 

    <ui:include src="/templates/includes/footer.xhtml"/>
    </h:body>
    </html>

这是我按下 menuitem Fabricant 时的页面 Fabricant

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/templates/template.xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<ui:define name="title">Liste Fabricants</ui:define>
<ui:define name="body">
<h:form id="form">  

    <p:growl id="growl" showDetail="true"/>  

    <p:commandLink  value="Ajouter Fabricant" action="#{fabricantbean.Ajouter()}"><img src="/image/ajout.jpg" alt= "Ajouter"></img></p:commandLink> 

    <p:dataTable id="cars" var="fab" value="#{fabricantbean.list}" paginator="true" rows="10"  rowKey="#{fab.idFabricant}"
                 selection="#{fabricantbean.selectitem}" selectionMode="single" emptyMessage="Aucun Fabricants Trouve">  

        <p:ajax event="rowSelect" listener="#{fabricantbean.onRowSelect}"   
                    update=":form:dialog :form:growl" oncomplete="carDialog.show()" />  

        <p:column  id="modelColumn" filterBy="#{fab.nomFabricant}"   
                headerText="Nom Fabricant" footerText="contains"  
                filterMatchMode="contains">  

            <h:outputText value="#{fab.nomFabricant}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                    Lien Site  
            </f:facet>  
            <h:outputText value="#{fab.lienSite}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                    Staut Fabricant  
            </f:facet>  
            <h:outputText value="#{fab.statutFabricant}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                    Nom Contact  
            </f:facet>  
            <h:outputText value="#{fab.nomContact}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                    Mail Contact  
            </f:facet>  
            <h:outputText value="#{fab.mailContact}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                    Action  
            </f:facet>  
            <p:commandButton value="Modifier" action="#{fabricantbean.Modifier()}"> 
            <f:setPropertyActionListener target="#{fabricantbean.selectitem}" value="#{fab}" /> 
            </p:commandButton>
            <p:commandButton value="Supprimer" onclick="info.show()"  >
            <f:setPropertyActionListener target="#{fabricantbean.selectitem}" value="#{fab}" />
            </p:commandButton>
        </p:column>  
    </p:dataTable>
  <p:confirmDialog id="infodialoge"    message="Si vous supprimer ce Fabricant vous resquer de supprimer ces composant ainsi les DEQ"
                header="supprimer Fabricant" severity="alert" widgetVar="info">  

        <p:commandButton id="confirm" value="Oui Sure"  oncomplete="info.hide()"  
                    action="#{fabricantbean.supprimer()}" update="form:cars"/>  
        <p:commandButton id="decline" value="Non " onclick="info.hide()" type="button" />   

    </p:confirmDialog>  

  <p:dialog id="dialog" header="Fabricant Detail" widgetVar="carDialog" resizable="false"  dynamic="true" 
                showEffect="fade" hideEffect="explode">  

        <h:panelGrid id="display" columns="2" cellpadding="4">  

            <f:facet name="header">  
                <p:graphicImage value="/images/cars/#{tableBean.selectedCar.manufacturer}.jpg"/>  
            </f:facet>  

            <h:outputText value="lien Reach:" />  
            <h:outputText value="#{fabricantbean.selectitem.lienReach}" />


            <h:outputText value="lien Fmd:" />  
            <h:outputText value="#{fabricantbean.selectitem.lienFmd}" />

            <h:outputText value="lien Rohs:" />  
            <h:outputText value="#{fabricantbean.selectitem.lienRohs}" />  

            <h:outputText value="lien cofc:" />  
            <h:outputText value="#{fabricantbean.selectitem.fichierCofc}" />  

            <h:outputText value="remarque:" />  
            <h:outputText value="#{fabricantbean.selectitem.remarqueFabricant}" />   

        </h:panelGrid>  

    </p:dialog> 
</h:form>  

</ui:define>

</ui:composition>
4

1 回答 1

7

问题实际上出url在您的menuitem.
你必须编辑你的Dirige方法。尝试以下操作:

public String Dirige(int a){
   setActiveindex(a);
   if (a == 1) {
      return "/pagess/pagesFabricant/Fabricant.jsf";
   }else{
      if (a == 2) {
         return "/pagess/pagesComposant/Composant.jsf";
      }else{
         ...
      }
   }
}

在您的模板中,您必须删除 url-Tags:

<h:form>
    <p:tabMenu activeIndex="#{loginBean.activeindex}">  
        <p:menuitem value="Home" url="Menu.jsf" icon="ui-icon-star" />
        <p:menuitem value="Fabricants" icon="ui-icon-wrench"   action="#{loginBean.Dirige(1)}" /> 
        <p:menuitem value="Composants" icon="ui-icon-search"  action="#{loginBean.Dirige(2)}"/> 
        <p:menuitem value="Dossier d'equivalence" icon="ui-icon-document" action="#{loginBean.Dirige(3)}"/> 
    </p:tabMenu> 
</h:form>
于 2013-04-19T09:15:31.527 回答