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>
Related
hello I have this page which work correctly and where I change pages dynamically
from bean with include tag:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="50" id="top">
<ui:include src="/WEB-INF/template/header.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="south" size="20">
<ui:include src="/WEB-INF/template/footer.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="west" size="400">
<h:form>
<f:ajax render=":centerContentPanel" execute="#this">
<h:commandLink value="page1" action="#{navigationBean.doNav}" update=":centerContentPanel">
<f:param name="test" value="/WEB-INF/pages/profil" />
</h:commandLink>
<h:commandLink value="page2" action="#{navigationBean.doNav}" process="#this">
<f:param name="test" value="/WEB-INF/pages/users" />
</h:commandLink>
</f:ajax>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" size="400">
<h:panelGroup id="centerContentPanel">
<ui:include src="#{navigationBean.pageName}.xhtml" />
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
In the included pages I have a dialog which contain and included page also.
When I open the dialog the screen stuck and I can't change anything or press anything it become like a disabled page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:form id="form">
<p:growl id="message" showDetail="true" globalOnly="true" />
<p:dataTable var="user" value="#{usersBean.users}" paginator="true"
reflow="true" widgetVar="multipleDT" resizableColumns="true"
id="multipleDT"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" selectionMode="single"
selection="#{usersBean.selectedUser}" rowKey="#{user.util}">
<p:ajax event="rowSelect" listener="#{usersBean.onRowSelect}"
update="b4 b3 :form:pickList :form:Submit" />
<p:ajax event="rowUnselect" listener="#{usersBean.onRowUnselect}"
update="b4 b3 :form:pickList :form:Submit" />
<p:column headerText="util" filterMatchMode="contains"
filterBy="#{user.util}" sortBy="#{user.util}" reflow="true">
<h:outputText value="#{user.util}" />
</p:column>
<p:column headerText="nom" filterMatchMode="contains"
filterBy="#{user.nom}" sortBy="#{user.nom}" reflow="true">
<h:outputText value="#{user.nom}" />
</p:column>
<p:column headerText="prenom" filterMatchMode="contains"
filterBy="#{user.prenom}" sortBy="#{user.prenom}" reflow="true">
<h:outputText value="#{user.prenom}" />
</p:column>
<p:column headerText="mail" filterMatchMode="contains"
filterBy="#{user.mail}" sortBy="#{user.mail}" reflow="true">
<h:outputText value="#{user.mail}" />
</p:column>
<f:facet name="footer">
<p:commandButton id="b3" value="ajouter"
oncomplete="PF('dlg3').show();" process="#this" ajax="true"
update="#widgetVar(dlg3) multipleDT">
</p:commandButton>
<p:commandButton id="b4" value="modifier"
disabled="#{usersBean.dis}" oncomplete="PF('dlg2').show();"
ajax="true" process="#this" update="#widgetVar(dlg2) multipleDT">
</p:commandButton>
</f:facet>
</p:dataTable>
<p:pickList id="pickList" value="#{usersBean.profilNonAffecte}"
var="Profil" itemLabel="#{Profil.libProfil}" itemValue="#{Profil}"
effect="bounce" responsive="true" showSourceFilter="true"
showTargetFilter="true" filterMatchMode="contains"
disabled="#{usersBean.dis}" style="width:50%;margin-top:20px;"
converter="primeFacesPickListConverter">
<f:facet name="sourceCaption">Available</f:facet>
<f:facet name="targetCaption">Starting</f:facet>
</p:pickList>
<p:commandButton id="Submit" value="Submit" style="margin-top:5px"
action="#{usersBean.commit}" update="pickList form:message"
disabled="#{usersBean.dis}" />
</h:form>
<h:form>
<p:dialog style="font-size:12px;" widgetVar="dlg3" resizable="false"
width="800" showEffect="explode" hideEffect="explode" modal="true"
id="dlg3" dynamic="true">
<ui:include src="/WEB-INF/pages/ajoutUser.xhtml" />
</p:dialog>
</h:form>
<h:form>
<p:dialog style="font-size:12px;" widgetVar="dlg2" resizable="false"
width="800" showEffect="explode" hideEffect="explode" modal="true"
id="dlg2" dynamic="true">
<ui:include src="/WEB-INF/pages/modifUser.xhtml" />
</p:dialog>
</h:form>
</ui:composition>
dialog code
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:panelGrid columns="2" id="grid">
<p:outputLabel for="ta4" value="date début :" />
<p:calendar id="ta4" value="#{usersBean.selectedUser.dateDeb}"
showOn="button" label="date début" required="true"
binding="#{startDateComponent}" pattern="dd/MM/yyyy" navigator="true">
<p:message for="ta4" />
<p:ajax event="dateSelect" listener="#{usersBean.onDateSelect}"
update="ta4" />
</p:calendar>
<p:outputLabel for="ta5" value="date fin :" />
<p:calendar id="ta5" value="#{usersBean.selectedUser.dateFin}"
showOn="button" label="date fin" required="true" pattern="dd/MM/yyyy"
mode="popup">
<f:validator validatorId="dateRangeValidator" />
<f:attribute name="startDateComponent" value="#{startDateComponent}" />
<p:message for="ta5" />
</p:calendar>
<p:outputLabel for="ta6" value="nom :" label="nom" />
<p:inputText rows="6" cols="33" id="ta6"
value="#{usersBean.selectedUser.nom}" required="true">
<p:message for="ta6" />
</p:inputText>
<p:outputLabel for="ta7" value="prénom :" />
<p:inputText rows="6" cols="33" id="ta7"
value="#{usersBean.selectedUser.prenom}" required="true"
label="prenom">
<p:message for="ta7" />
</p:inputText>
<p:outputLabel for="ta8" value="mail :" />
<p:inputText rows="6" cols="33" id="ta8"
value="#{usersBean.selectedUser.mail}" required="true" label="mail"
validatorMessage="email format error ">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
<p:message for="ta8" />
</p:inputText>
<p:outputLabel for="chk" value="Valid :" />
<p:selectBooleanCheckbox value="#{usersBean.selectedUser.valid}"
id="chk" />
<p:commandButton value="confirmer" id="ajax"
actionListener="#{usersBean.modifier}"
styleClass="ui-priority-primary" update="grid form:message form:multipleDT" >
</p:commandButton>
</h:panelGrid>
</ui:composition>
i find it the problem was modal="true" in the dialog
I have an issue with the footer row that i need to display in primefaces. In UI there is an extra space that comes up between the grid and the footer row which is kind of annoying. Is there anything that is going wrong. Any suggestions are most welcome. Please find my below code.
<!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:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
</h:head>
<body style="height: 90%">
<ui:composition template="template/common/commonPrimefacesLayout.xhtml">
<ui:define name="content">
<h:form id="searchFormForResult" prependId="false">
<h:inputHidden id="rowId" value="#{MBean.selectedRowId}"></h:inputHidden>
<p:accordionPanel style="align:top;margin" prependId="false">
<p:tab title="Search Items">
<p:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="expenseDesc" value=" Description: " />
<p:selectOneMenu id="expenseDesc" widgetVar="expenseDesc" value="#{searchMBean.searchCriteria.shortDesc}" style="width:150px" editable="true" filter="true" filterMatchMode="startsWith">
<f:selectItem itemLabel="All" itemValue="All" noSelectionOption="false"/>
<f:selectItems value="#{searchMBean.shortDescriptionList}" />
</p:selectOneMenu>
</p:panelGrid>
<p:commandButton id="Reset" actionListener="#{searchMBean.resetForm}" value="Reset" ajax="false" style="float:right;" onclick="resetSearchForm()"></p:commandButton>
<p:commandButton id="Submit" action="#{searchMBean.search}" value="Submit" ajax="false" style="float:right;"></p:commandButton>
</p:tab>
</p:accordionPanel>
<p:panel>
<h:outputLabel value="Search Results" style="font-weight: bold;"></h:outputLabel>
<p:dataTable id="SearchResult" var="SearchResult" value="#{searchMBean.searchResult}" selection="#{MBean.itemsSearchResult}" rowKey="#{searchResult.id}" scrollable="true" rowSelectMode="multiple" scrollHeight="65%">
<p:column selectionMode="multiple" style="width:5%;"/>
<p:column>
<f:facet name="header">
<h:outputText value="Contact Name" />
</f:facet>
<h:outputText value="#{mBean.name}" />
<f:facet name="footer">
<h:outputText value="#{mBean.name}" />
</f:facet>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Contact Address" />
</f:facet>
<h:outputText value="#{mBean.addr}" />
<f:facet name="footer">
<h:outputText value="#{mBean.name}" />
</f:facet>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Actions" />
</f:facet>
<p:commandButton action="#{MBean.display}" icon="ui-icon ui-icon-search" title="ViewButton" oncomplete="disableFields('singleRowView');">
<f:param name="itemId" value="#{searchResult.id}"></f:param>
</p:commandButton>
<p:commandButton action="#{MBean.display}" icon="ui-icon ui-icon-pencil" title="UpdateButton" oncomplete="disableFields('singleRowView');">
<f:param name="itemId" value="#{Result.id}"></f:param>
</p:commandButton>
<p:commandButton id="delete"
icon="ui-icon ui-icon-trash"
action="#{MBean.ItemRow}"
onclick="setSelectedRowId('rowId',#{result.id})"
title="GDeleteButton">
<p:confirm header="Delete Record"
message="Are you sure about deleting this record?"
icon="ui-icon-alert"/>
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade">
<p:commandButton title="GDelYesButton" value="Yes" styleClass="ui-confirmdialog-yes"/>
<p:commandButton title="GDelNoButton" value="No" onclick="PF('confirmation').hide()" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
</p:column>
</p:dataTable>
<p:panelGrid id="groupActions" columns="5">
<p:commandButton action="#{MBean.viewItems}" icon="ui-icon ui-icon-search" value="View" title="GViewButton" oncomplete="disableFields('groupView');">
</p:commandButton>
<p:commandButton action="#{MBean.viewItems}" icon="ui-icon ui-icon-pencil" value="Update" title="GUpdateButton" oncomplete="disableFields('groupView');">
</p:commandButton>
<p:button outcome="createItem" value="Add New" title="AddNewButton"/>
<p:commandButton id="delete" action="#{MBean.delete}" icon="ui-icon ui-icon-trash" value="Delete" title="Delete" >
<p:confirm header="Delete Record" message="Are you sure about deleting this record?" icon="ui-icon-alert"/>
</p:commandButton>
<p:commandButton actionListener="#{searchMBean.resetForm}" value="Cancel" title="Cancel" ajax="false"></p:commandButton>
</p:panelGrid>
<p:confirmDialog global="true" showEffect="fade">
<p:commandButton title="Yes" value="Yes" styleClass="ui-confirmdialog-yes" />
<p:commandButton title="No" value="No" styleClass="ui-confirmdialog-no" onclick="PF('groupDeleteConfirm').hide()" />
</p:confirmDialog>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
Also please find the image of the behaviour. The extra spaace that is coming between grid and the footer. Please help.
I have this .xhtml file. It's a data table page with three buttons (one for creating users, one for editing them and one for deleting them). Creating and deleting users are working but updating not. When I call the method actionListener="#{usuariosBean.actualizarUsuario}", I get all parameters well but not the Id, I'm getting 0 instead of the real Id of the user.
I have tried to do it in different .xhtml and it work good so I think that the problem is about the .xhtml file but... I don't know. Could anybody help me? Thanks a lot!!!
<?xml version='1.0' encoding='UTF-8' ?>
<!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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="./../template.xhtml">
<ui:define name="content">
<p:growl id="msgs" showDetail="true" />
<h:form>
<p:commandButton update=":formCrear" icon="ui-icon-document"
title="Crear Usuario" value="Crear Usuario"
oncomplete="PF('usuarioDialogCrear').show();">
</p:commandButton>
</h:form>
<h:form id="form">
<p:dataTable var="usuario" value="#{usuariosBean.usuarios}"
paginator="true" rows="10">
<p:column headerText="Id">
<h:outputText value="#{usuario.id}" />
</p:column>
<p:column headerText="Nombre de Usuario">
<h:outputText value="#{usuario.nombreDeUsuario}" />
</p:column>
<p:column headerText="Contraseña">
<h:outputText value="#{usuario.contrasenya}" />
</p:column>
<p:column headerText="Rol">
<h:outputText value="#{usuario.rol}" />
</p:column>
<p:column headerText="" style="text-align:center; width:4%">
<p:commandButton update=":form:usuarioActualizar" id="Actualizar"
icon="ui-icon-pencil" title="Actualizar"
oncomplete="PF('usuarioDialogActualizar').show();">
<f:setPropertyActionListener value="#{usuario}"
target="#{usuariosBean.usuarioSeleccionado}" />
</p:commandButton>
</p:column>
<p:column headerText="" style="text-align:center; width:4%">
<p:commandButton update=":form:usuarioEliminar" id="Eliminar"
icon="ui-icon-close" title="Eliminar"
oncomplete="PF('confirmacion').show();">
<f:setPropertyActionListener value="#{usuario}"
target="#{usuariosBean.usuarioSeleccionado}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Actualizar Usuario"
widgetVar="usuarioDialogActualizar" modal="true" showEffect="fade"
hideEffect="explode" resizable="false" width="400">
<p:outputPanel id="usuarioActualizar" style="text-align:center;"
layout="block">
<p:panelGrid columns="2">
<h:outputText value="Id " />
<p:inputText
value="#{usuariosBean.usuarioSeleccionado.id}"
style="font-weight:bold" size="37" />
<h:outputText value="Usuario: " />
<p:inputText
value="#{usuariosBean.usuarioSeleccionado.nombreDeUsuario}"
style="font-weight:bold" size="37" />
<h:outputText value="Contraseña: " />
<p:inputText
value="#{usuariosBean.usuarioSeleccionado.contrasenya}"
style="font-weight:bold" size="37" />
<h:outputText value="Rol " />
<p:inputText value="#{usuariosBean.usuarioSeleccionado.rol}"
style="font-weight:bold" size="37" />
</p:panelGrid>
</p:outputPanel>
<f:facet name="footer">
<p:commandButton update=":form, :msgs" id="btnActualizarAceptar"
icon="ui-icon-disk" title="Guardar Usuario"
value="Actualizar Usuario"
actionListener="#{usuariosBean.actualizarUsuario}"
oncomplete="PF('usuarioDialogActualizar').hide()">
</p:commandButton>
<p:commandButton id="btnActualizarCancelar" icon="ui-icon-close"
title="Cancelar" value="Cancelar" type="button"
onclick="PF('usuarioDialogActualizar').hide()">
</p:commandButton>
</f:facet>
</p:dialog>
<p:confirmDialog
message="¿Está seguro que desea eliminar el usuario?"
showEffect="bounce" hideEffect="explode" header="Eliminar Usuario"
severity="alert" widgetVar="confirmacion">
<p:outputPanel id="usuarioEliminar" style="text-align:center;"
layout="block">
<h:inputHidden value="#{usuariosBean.usuarioSeleccionado.id}" />
</p:outputPanel>
<p:commandButton id="confirmarDialogo" value="Aceptar"
icon="ui-icon-check" update=":form, :msgs"
oncomplete="PF('confirmacion').hide()"
actionListener="#{usuariosBean.eliminarUsuario}" />
<p:commandButton id="cancelarDialogo" icon="ui-icon-close"
title="Cancelar" value="Cancelar"
oncomplete="PF('confirmacion').hide()">
</p:commandButton>
</p:confirmDialog>
</h:form>
<h:form id="formCrear">
<p:dialog header="Crear Usuario" widgetVar="usuarioDialogCrear"
modal="true" showEffect="fade" hideEffect="explode"
resizable="false" width="400">
<p:outputPanel id="usuarioCrear" style="text-align:center;"
layout="block">
<p:panelGrid columns="2">
<h:outputText value="Usuario: " />
<p:inputText value="#{usuariosBean.nombreDeUsuario}"
required="true" size="37" />
<h:outputText value="Contraseña: " />
<p:inputText value="#{usuariosBean.contrasenya}" required="true"
size="37" />
<h:outputText value="Rol " />
<p:inputText value="#{usuariosBean.rol}" required="true"
size="37" />
</p:panelGrid>
</p:outputPanel>
<f:facet name="footer">
<p:commandButton update=":form, :msgs" id="btnCrearAceptar"
icon="ui-icon-disk" title="Guardar Usuario"
value="Guardar Usuario" action="#{usuariosBean.guardarUsuario}"
oncomplete="PF('usuarioDialogCrear').hide()">
</p:commandButton>
<p:commandButton id="btnCrearCancelar" icon="ui-icon-close"
title="Cancelar" value="Cancelar"
oncomplete="PF('usuarioDialogCrear').hide()">
</p:commandButton>
</f:facet>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
Well, my problem is that no dialog inside my main page is called. I.E: I have a commandButton should call "varDialogFindPacientes" but don't work. I don't know what can i do to fix it.
Look my main page:
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:head>
</h:head>
<h:body>
<ui:composition>
<p:dialog id="dialogCadastrar" width="900px" height="500px"
header="Cadastrar Orçamento" widgetVar="varDialogCadastrar"
modal="true" showEffect="fade" hideEffect="fade">
<h:form id="formCadastrar">
<p:panelGrid id="panelGridCadastar" styleClass="semBorda"
columns="2">
<h:outputText value="Data Emissão: " />
<p:inputText id="dataEmissao"
value="#{orcamentoMB.orcamento.dataEmissao}" readonly="true">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:inputText>
<h:outputText value="Data Validade: " />
<p:inputText id="dataValidade"
value="#{orcamentoMB.orcamento.dataValidade}" readonly="true">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:inputText>
<h:outputText value="Situação " />
<p:inputText id="situacao"
value="#{orcamentoMB.orcamento.situacao.descricao}"
readonly="true" />
<h:outputText value="Desconto (%): " />
<p:panelGrid columns="2" styleClass="semBorda">
<pe:inputNumber value="#{orcamentoMB.orcamento.desconto}"
id="desconto" symbol=" %" symbolPosition="suffix"
validatorMessage="O desconto não pode ser maior que #{orcamentoMB.maxDesconto} %">
<f:validateDoubleRange maximum="#{orcamentoMB.maxDesconto}" />
</pe:inputNumber>
<p:commandButton value="Recalcular" process="desconto"
icon="ui-icon-refresh"
update=":formCadastrar:totalGeral, :formCadastrar:totalGeralComDesconto" />
</p:panelGrid>
<h:outputText value="Observação: " />
<p:inputTextarea value="#{orcamentoMB.orcamento.observacoes}"
rows="5" cols="30" />
<h:outputText value="Dentista: *" />
<p:panel style="border:1px solid #e5e5e5;">
<p:inputText required="true"
requiredMessage="Selecione um dentista"
value="#{orcamentoMB.orcamento.dentistaOrcou.pessoaFisica.nome}"
readonly="true" size="30" id="dentistaOrcou" />
<p:commandButton icon="ui-icon-search" type="button"
onclick="varDialogFindDentistas.show()" />
</p:panel>
<h:outputText value="Paciente *" />
<p:panel style="border:1px solid #e5e5e5;">
<p:inputText required="true"
requiredMessage="Selecione um paciente"
value="#{orcamentoMB.orcamento.paciente.pessoaFisica.nome}"
readonly="true" size="30" id="paciente" />
<p:commandButton icon="ui-icon-search" type="button"
onclick="varDialogFindPacientes.show()" />
</p:panel>
</p:panelGrid>
<p:toolbar>
<p:toolbarGroup align="left">
<p:commandButton value="Add" icon="ui-icon-plus"
onclick="varDialogFindItensTabela.show()" type="button"
update=":formCadastrar:dataTableItens, :formCadastrar:salvarAceitando,:formCadastrar:salvarSemAceitar, :formCadastrar:totalGeral,
:formCadastrar:totalGeralComDesconto" />
<p:commandButton value="Del" icon="ui-icon-minus"
disabled="#{orcamentoMB.selectedItemOrcamento == null}"
actionListener="#{orcamentoMB.delItemOrcamento}"
update=":formCadastrar:dataTableItens, :formCadastrar:totalGeral,
:formCadastrar:totalGeralComDesconto, :formCadastrar:salvarAceitando,:formCadastrar:salvarSemAceitar" />
</p:toolbarGroup>
</p:toolbar>
<p:dataTable rowKey="#{item}" var="item"
value="#{orcamentoMB.itens}"
emptyMessage="Não foi encontrado nenhum registro"
id="dataTableItens"
selection="#{orcamentoMB.selectedItemOrcamento}"
selectionMode="single" rowIndexVar="rowIndex"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'first-row' : 'second-row'}">
<p:column headerText="Nome"
sortBy="#{item.itemTabelaProcedimento.procedimento.nome}"
id="nome">
<h:outputText
value="#{item.itemTabelaProcedimento.procedimento.nome}" />
</p:column>
<p:column headerText="Valor"
sortBy="#{item.itemTabelaProcedimento.valor}" id="valor">
<h:outputText value="#{item.itemTabelaProcedimento.valor}">
<f:convertNumber currencySymbol="R$ " type="currency" />
</h:outputText>
</p:column>
<p:column headerText="Local Aplicação"
sortBy="#{item.localAplicacao.descricao}" id="localAplicacao">
<h:outputText value="#{item.localAplicacao.descricao}" />
</p:column>
<p:column headerText="Dente" sortBy="#{item.dente.descricao}"
id="dente">
<h:outputText value="#{item.dente.descricao}" />
</p:column>
<p:column headerText="Face"
sortBy="#{item.faceAplicacao.descricao}" id="face">
<h:outputText value="#{item.faceAplicacao.descricao}" />
</p:column>
</p:dataTable>
<p:panelGrid columns="2">
<h:outputText value="Total Geral: " />
<h:outputText value="#{orcamentoMB.totalGeral}" id="totalGeral">
<f:convertNumber currencySymbol="R$ " type="currency" />
</h:outputText>
<h:outputText value="Total Com Desconto: " />
<h:outputText value="#{orcamentoMB.totalGeralComDesconto}"
id="totalGeralComDesconto">
<f:convertNumber currencySymbol="R$ " type="currency" />
</h:outputText>
</p:panelGrid>
<p:toolbar>
<p:toolbarGroup align="left">
<p:commandButton icon="ui-icon-disk" value="Salvar Sem Aceitar"
id="salvarSemAceitar" disabled="#{orcamentoMB.itens.size() == 0}"
actionListener="#{orcamentoMB.salvar}"
oncomplete="if (!args.validationFailed){ varDialogCadastrar.hide() }"
update=":formOrcamentos:dataTableOrcamentos">
<f:attribute name="salvarAceitando" value="false" />
</p:commandButton>
<p:commandButton icon="ui-icon-disk" value="Salvar Aceitando"
id="salvarAceitando" disabled="#{orcamentoMB.itens.size() == 0}"
actionListener="#{orcamentoMB.salvar}"
oncomplete="if (!args.validationFailed){ varDialogCadastrar.hide() }"
update=":formOrcamentos:dataTableOrcamentos">
<f:attribute name="salvarAceitando" value="true" />
</p:commandButton>
<p:commandButton value="Cancelar" icon="ui-icon-close"
onclick="varDialogCadastrar.hide()" type="button" />
</p:toolbarGroup>
</p:toolbar>
</h:form>
</p:dialog>
</ui:composition>
</h:body>
</html>
So, i'll show a page the is called for "varDialogFindPacientes"
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition>
<p:dialog id="dialogFindPacientes" width="600px" height="auto"
header="Pesquisar Pacientes" widgetVar="varDialogFindPacientes"
modal="true" showEffect="fade" hideEffect="fade">
<h:form id="formFindPacientes">
<p:dataTable rowKey="#{paciente.id}" var="paciente"
value="#{orcamentoMB.pacientes}" paginator="true"
emptyMessage="Não foi encontrado nenhum registro" rows="20"
id="dataTablePacientes" selection="#{orcamentoMB.selectedPaciente}"
selectionMode="single" rowIndexVar="rowIndex"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'first-row' : 'second-row'}"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<p:ajax event="rowDblselect" process="dataTablePacientes"
listener="#{orcamentoMB.updatePacienteFromFind}"
oncomplete="dialogFindPacientes.hide()"
update=":formCadastrar:paciente" />
<p:column headerText="Nome" sortBy="#{paciente.pessoaFisica.nome}"
filterBy="#{paciente.pessoaFisica.nome}" id="nome"
filterMatchMode="contains">
<h:outputText value="#{paciente.pessoaFisica.nome}" />
</p:column>
</p:dataTable>
</h:form>
</p:dialog>
</ui:composition>
</h:body>
</html>
EDIT 1:
I have another problem yet, the #PostConstruct from my ManagedBean is called every ajax call.
Well, I have a p:dialog that inserts a new Entity, but after this entity is saved into database the p:dataTable remains the same, the new row doesn't appear.
Look at my p:dialog:
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition>
<h:form id="formCadastrar">
<p:dialog width="900px" height="500px" header="Cadastrar Dentista"
widgetVar="dialogCadastrar" modal="true">
<p:panelGrid columns="2" styleClass="semBorda">
<p:commandButton icon="ui-icon-disk" value="Salvar"
actionListener="#{dentistaMB.salvar}"
update=":formDentistas:dataTableDentistas" />
<p:commandButton value="Cancelar" icon="ui-icon-close"
onclick="confirmCancelar.show()" type="button" />
</p:panelGrid>
<p:panelGrid id="panelGridCadastar" styleClass="semBorda"
columns="2">
<h:outputText value="Nome: *" />
<p:inputText id="nome"
value="#{dentistaMB.dentista.pessoaFisica.nome}" size="40"
required="true" requiredMessage="O Nome do Dentista é obrigatório">
</p:inputText>
<h:outputText value="CRO *" />
<p:inputText id="cro" value="#{dentistaMB.dentista.cro}" size="10"
required="true" requiredMessage="O Número do CRO é obrigatório" />
</p:panelGrid>
<p:panelGrid columns="2" styleClass="semBorda">
<p:commandButton icon="ui-icon-disk" value="Salvar"
actionListener="#{dentistaMB.salvar}"
update=":formDentistas:dataTableDentistas" />
<p:commandButton value="Cancelar" icon="ui-icon-close"
onclick="confirmCancelar.show()" />
</p:panelGrid>
<p:confirmDialog id="confirmCancelar" message="Deseja cancelar ?"
showEffect="fade" hideEffect="fade" header="Cancelar"
severity="alert" widgetVar="confirmCancelar" appendToBody="true">
<p:commandButton value="Sim" oncomplete="confirmCancelar.hide()"
actionListener="#{dentistaMB.cancelar}" />
<p:commandButton value="Não" onclick="confirmCancelar.hide()"
type="button" />
</p:confirmDialog>
</p:dialog>
</h:form>
</ui:composition>
</h:body>
</html>
And look at my p:dataTable
<h:form id="formDentistas">
<p:growl autoUpdate="true" id="growlmessages" />
<p:dataTable rowKey="#{dentista.id}" var="dentista" value="#{dentistaMB.dentistas}"
paginator="true" emptyMessage="Não foi encontrado nenhum registro"
rows="10" id="dataTableDentistas"
selection="#{dentistaMB.selectedDentista}" selectionMode="single">
<f:facet name="header">Lista de Dentistas</f:facet>
<p:column headerText="Nome" sortBy="nome" filterBy="nome" id="nome"
width="200px">
#{dentista.pessoaFisica.nome}
</p:column>
<p:column headerText="Data Nascimento" sortBy="dataNascimento"
filterBy="dataNascimento" id="dataNascimento" width="60px">
#{dentista.pessoaFisica.dataNascimento}
</p:column>
<p:column headerText="CRO" sortBy="cro" filterBy="cro" id="cro"
width="60px">
#{dentista.cro}
</p:column>
<f:facet name="footer">
<div class="align_text_left">
<p:commandButton icon="ui-icon-plus" value="Novo" id="cadastrar"
oncomplete="dialogCadastrar.show()" />
<p:column headerText="Ações" style="width:50px;">
<p:commandButton value="Alterar" icon="ui-icon-pencil" />
<p:commandButton value="Remover" icon="ui-icon-trash"
action="#{dentistaMB.deletar}"
update=":formDentistas:dataTableDentistas" />
</p:column>
</div>
</f:facet>
</p:dataTable>
</h:form>
So, what's the correct form to update the p:dataTable after a change in an entity? This example above is about an insert, but remove doesn't work either. I used the following code:
<p:commandButton value="Remover" icon="ui-icon-trash"
action="#{dentistaMB.deletar}"
update=":formDentistas:dataTableDentistas" />
in your dialog you must add an ajax event to fire update of form like:
<p:ajax event="close" listener="#{dentistaMB.load}"
update=":formDentistas" immediate="true" global="false" />
this will allow you to reload your table feed lists.
in your load method you need to update (refetch data from db) dentistas list. If you are using filtering do not forget to update your filtering list as well.
In managedbean load function you can use:
public void load(){
dentistas.clear();
filteredDentistas.clear();
dentistas.addAll(getDentistService().getDentists());
filteredDentistas.addAll(getDentistService().getDentists());
}