我的<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);
}
}
当我点击任何菜单项时,不会调用action方法。我做了一些调试,以确保不调用该方法。或者,该方法正在使用<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>
答案 0 :(得分: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{
...
}
}
}
在您的模板中,您必须删除网址标签:
<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>