Action method is not working in my <p:menuitem>
. I would like to change activeIndex
via an action method of <p:menuitem>
.
The code below is the code on template page that is used in my pages:
<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>
This is my bean:
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);
}
}
When I click on any menu item the action method is not called. I did some debugging to ensure that the method is not called. Alternatively, the method is working with <p:commandButton>
.
This is the template
<!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>
This is page Fabricant when I press menuitem 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>
the problem is in fact the url
in your menuitem
.
You have to edit your Dirige
method.
Try the following:
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{
...
}
}
}
and in your template you have to remove the 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With