How can I update a primefaces datatable summary row after submitting a form (dialog)?
The datatable is already updated correctly after some CRUD operation, but the summary row doesn't. I'm using p:remoteCommand to update the summary row when filtering the datatable and it works fine.
The List.xhtml:
<h:form id="TreinamentosListForm">
<p:panel header="#{treinaBundle.ListTreinamentosTitle}" >
<p:remoteCommand name="updateFooterSumCountId" update="datalist:footerSumCountId" />
<p:dataTable id="datalist"
filteredValue="#{treinamentosController.filteredTreinamentos}"
value="#{treinamentosController.items}"
var="item"
rowKey="#{item.id}"
paginator="true"
selectionMode="single"
selection="#{treinamentosController.selected}">
<p:ajax event="filter" process="#form" update="#this" listener="#{treinamentosController.onFilter}" oncomplete="updateFooterSumCountId()" />
<p:ajax event="rowSelect" update=":TreinamentosListForm:createButton :TreinamentosListForm:viewButton :TreinamentosListForm:editButton :TreinamentosListForm:deleteButton :TreinamentosListForm:TreinamentosDataTableContextMenu" listener="#{treinamentosController.resetParents}"/>
<p:ajax event="rowUnselect" update=":TreinamentosListForm:createButton :TreinamentosListForm:viewButton :TreinamentosListForm:editButton :TreinamentosListForm:deleteButton :TreinamentosListForm:TreinamentosDataTableContextMenu" listener="#{treinamentosController.resetParents}"/>
<p:ajax event="rowDblselect" onsuccess="document.getElementById('TreinamentosListForm:viewButton').click();"/>
<p:column sortBy="#{item.id}" filterBy="#{item.id}" style="text-align: right">
<f:facet name="header">
<h:outputText value="#{treinaBundle.ListTreinamentosTitle_id}"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:columnGroup id="totalGroup" rendered="true" type="footer" >
<p:row>
<p:column style="text-align:right">
<f:facet name="footer">
<!-- the summary row: -->
<h:outputText id="footerSumCountId" value="#{treinamentosController.sumCountId}" />
</f:facet>
</p:column>
</p:row>
</p:columnGroup>
</p:dataTable>
<f:facet name="header">
<p:commandButton id="createButton" icon="ui-icon-plus" value="#{treinaBundle.Create}" actionListener="#{treinamentosController.prepareCreate}" update=":TreinamentosCreateForm" oncomplete="PF('TreinamentosCreateDialog').show()"/>
<p:commandButton id="viewButton" icon="ui-icon-search" value="#{treinaBundle.View}" update=":TreinamentosViewForm" oncomplete="PF('TreinamentosViewDialog').show()" disabled="#{empty treinamentosController.selected}"/>
<p:commandButton id="editButton" icon="ui-icon-pencil" value="#{treinaBundle.Edit}" update=":TreinamentosEditForm" oncomplete="PF('TreinamentosEditDialog').show()" disabled="#{empty treinamentosController.selected}"/>
<p:commandButton id="deleteButton" icon="ui-icon-trash" value="#{treinaBundle.Delete}" actionListener="#{treinamentosController.delete}" update=":growl,datalist" disabled="#{empty treinamentosController.selected}">
<p:confirm header="#{treinaBundle.ConfirmationHeader}" message="#{treinaBundle.ConfirmDeleteMessage}" icon="ui-icon-alert"/>
</p:commandButton>
</f:facet>
</p:panel>
<ui:include src="/WEB-INF/include/confirmation.xhtml"/>
</h:form>
The Create.xhtml:
<p:dialog id="TreinamentosCreateDlg" widgetVar="TreinamentosCreateDialog" modal="true" resizable="false" appendTo="#(body)" header="#{treinaBundle.CreateTreinamentosTitle}" closeOnEscape="true" >
<h:form id="TreinamentosCreateForm">
<h:panelGroup id="display" rendered="#{treinamentosController.selected != null}">
<p:panelGrid columns="2" columnClasses="column">
<p:outputLabel value="#{treinaBundle.CreateTreinamentosLabel_id}" for="id" />
<p:outputLabel id="id" value="Value automatically generated from database." title="#{treinaBundle.CreateTreinamentosTitle_id}" />
</p:panelGrid>
<p:commandButton actionListener="#{treinamentosController.saveNew}" value="#{treinaBundle.Save}" update="#all,display,:TreinamentosListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,PF('TreinamentosCreateDialog'));">
<p:confirm header="#{treinaBundle.ConfirmationHeader}" message="#{treinaBundle.ConfirmCreateMessage}" icon="ui-icon-alert"/>
</p:commandButton>
<p:commandButton value="#{treinaBundle.Cancel}" onclick="PF('TreinamentosCreateDialog').hide()"/>
</h:panelGroup>
</h:form>
</p:dialog>
Thanks in advance.
After reading the Primefaces 5 documentation, what I did was to invoke (in the Create.xhtml) the Primefaces filter method, referencing through the widgetVar defined in the target datatable (in List.xhtml). Doing so, it triggers my p:remoteCommand, which in its turn, triggers the update for the summary row:
<p:commandButton actionListener="#{treinamentosController.saveNew}" value="#{treinaBundle.Save}" update="#this,display,:TreinamentosListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,PF('TreinamentosCreateDialog'),PF('treinamentosTable').filter());" >
<p:confirm header="#{treinaBundle.ConfirmationHeader}" message="#{treinaBundle.ConfirmCreateMessage}" icon="ui-icon-alert"/>
</p:commandButton>
If someone has a more elegant solution, please share. I had not time
Related
is it possible to keep the behaviour more stable?
what I have:
an Tree table with 3 columns, first has collapsed stuff in it
if I open one and close it, then click on sort
it is open after that
what I would like to have:
keep it closed if it was closed before sort
<h:form id="form">
<p:treeTable value="#{ttBasicView.root}" var="document">
<f:facet name="header">
FritzBox Smart Home Daten
</f:facet>
<p:column headerText="Name" >
<h:outputText value="#{document.name}" />
</p:column>
<p:column headerText="Gesamtverbrauch (in kWh)" sortBy="#{document.gesamtverbrauch}" actionListener="#{BasicView.expandAll}">
<h:outputText value="#{document.gesamtverbrauch}" />
</p:column>
<p:column headerText="aktuelle Temperatur" sortBy="#{document.akttemperatur}">
<h:outputText value="#{document.akttemperatur}" />
</p:column>
<p:column style="width:24px">
<p:commandLink update=":form:documentPanel" oncomplete="PF('documentDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{document}" target="#{ttBasicView.selectedDocument}" />
</p:commandLink>
</p:column>
</p:treeTable>
<p:dialog id="dialog" header="Document Detail" showEffect="fade" widgetVar="documentDialog" modal="true" resizable="false">
<p:outputPanel id="documentPanel">
<p:panelGrid columns="2" columnClasses="label,value" rendered="#{not empty ttBasicView.selectedDocument}">
<h:outputLabel for="name" value="Name: " />
<h:outputText id="name" value="#{ttBasicView.selectedDocument.name}" style="font-weight:bold" />
<h:outputLabel for="gesamtverbrauch" value="Gesamtverbrauch: " />
<h:outputText id="gesamtverbrauch" value="#{ttBasicView.selectedDocument.gesamtverbrauch}" style="font-weight:bold" />
<h:outputLabel for="akttemperatur" value="aktuelle Temperatur: " />
<h:outputText id="akttemperatur" value="#{ttBasicView.selectedDocument.akttemperatur}" style="font-weight:bold" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
That was my problem too.
Try it in your treeTable :
<p:ajax event="collapse"
onstart="handleLoadingStarted()"
oncomplete="handleLoadingStopped()" />
I want to implement a sort and/or filter-function for my datatable, and I have done everything the documentation says.
The problem is, that if I klick on a sort-header or fill in a filter, nothing happens (even the ajax-symbol is not shown to i assume that nothing happens at all).
What can be the problem?
I am using:
templates to show the p:datatable
primefaces 5.1
myfaces bundle 2.2.0-20131222.194304-2575.jar
code:
<ui:define name="content">
<h:form>
<p:dataTable var="user" value="#{logbookProjectMembersBean.projectMembers}"
filterDelay="100" widgetVar="userList" emptyMessage="No ProjectMembers found with given criteria"
filteredValue="#{logbookProjectMembersBean.filteredProjectMembers}" rowStyleClass="#{user.enabled? 'row' : 'inactiveUserRow'}" styleClass="userList">
<f:facet name="header">
<p:outputPanel>
<h:outputText>Overview</h:outputText>
<h:outputText value=" - Search:" />
<p:inputText id="globalFilter" onkeyup="PF('userList').filter()" style="width:150px" placeholder="Enter keyword" />
</p:outputPanel>
</f:facet>
<p:column headerText="Name" filterBy="#{user.name}" filterMatchMode="contains" >
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Surname" filterBy="#{user.surname}" filterMatchMode="contains" >
<h:outputText value="#{user.surname}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
I have a DataTable and edit a listing you have to open the Dialog component with the respective values that sends the selected object from theDataTable, but cannot open. I have noticed that the function is REQUIRED = "true" and also that no error is displayed, the only solution that helped me erase the function is REQUIRED.
How do I to bring up the Dialog component without taking the REQUIRED function. An example of the code:
<p:tab id="tab_listar" title="#{msg.labelListar}">
<h:form id="form_mostrar_listado">
<p:dialog id="ModificarLugar" header="Modificar Datos" widgetVar="LugarDialogo2"
modal="false" resizable="false" hideEffect="bounce" showEffect="explode">
<h:panelGrid id="ModificarLugar1" columns="2" cellpadding="5">
<h:outputText value="#{msg.labelCodigo}"/>
<h:outputText value="#{BeanLugar.objLugarMod.cod_lugar}"/>
<h:outputText value="#{msg.labelNombre}"/>
<p:inputText value="#{BeanLugar.objLugarMod.nombre}" id="nombre_lu_mod"
required="true" requiredMessage="#{msg.labelNoVacio}"
validatorMessage="#{msg.labelNoValido}"> </p:inputText>
<h:outputText value="#{msg.labelUbicacion}"/>
<h:panelGroup>
<p:selectOneMenu value="#{BeanLugar.objLugarMod.objPais.cod_pais}"
required="true" id="cod_pais_mod" effect="fade"
requiredMessage="#{msg.labelNoVacio}"
validatorMessage="#{msg.labelNoValido}">
<f:selectItem itemLabel="#{msg.labelEligePais}" itemValue=""/>
<f:selectItems value="#{Pais.cargarComboPais}"/>
</p:selectOneMenu>
<h:message showDetail="false" showSummary="true" for="cod_pais_mod"/>
</h:panelGroup>
<p:commandButton value="Cancelar" actionListener="#{BeanLugar.doiniciarModLugar()}"
update=":LugarTabView:form_mostrar_listado" icon="ui-icon-triangl-1-w"
immediate="true"> </p:commandButton>
<p:commandButton id="btn_actualizar" value="#{msg.btnActualizar}"
update=":LugarTabView:form_mostrar_listado"
actionListener="#{BeanLugar.doActualizaLugar()}"> </p:commandButton>
</h:panelGrid>
</p:dialog>
<p:panel id="datListadoLugar">
<h:outputText value="#{msg.labelListado}"/>
<h:panelGrid columns="3" cellspacing="10" width="100">
<p:commandButton value="#{msg.btnNuevo}" update="form_mostrar_listado"
actionListener="#{BeanLugar.doiniciarListadoLugar()}"/>
<p:commandButton value="#{msg.btnListar}" update="form_mostrar_listado"
actionListener="#{BeanLugar.doListarLugar()}"/>
</h:panelGrid>
<h:panelGrid columns="2" rendered="#{BeanLugar.sizeLugar ne '0'}">
<h:outputText value="#{msg.labelCantidad}"/>
<h:outputText value="#{BeanLugar.arrLugar.size()}"/>
</h:panelGrid>
<h:panelGrid columns="1" rendered="#{BeanLugar.sizeLugar ne '0'}">
<p:dataTable id="resListadoLugar" value="#{BeanLugar.doListarLugar()}" var="ls"
paginator="true" rows="5" paginatorPosition="both" rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="#{msg.labelLugar}"/>
</f:facet>
<h:outputText value="#{ls.nombre}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg.labelUbicacion}"/>
</f:facet>
<h:outputText value="#{ls.objPais.nomb_pais}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg.labelVer}"/>
</f:facet>
<p:commandLink title="Ver" action="#{BeanLugar.mostrarLugar(ls)}"
value="Ver" update=":LugarTabView:form_mostrar_listado:DetalleLugar"
oncomplete="LugarDialogo.show()"> </p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg.labelEditar}"/>
</f:facet>
<p:commandLink title="Editar" action="#{BeanLugar.editarLugar(ls)}"
value="Editar"
update=":LugarTabView:form_mostrar_listado:ModificarLugar"
oncomplete="LugarDialogo2.show()"> </p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg.labelEliminar}"/>
</f:facet>
<p:commandLink title="Eliminar" action="#{BeanLugar.eliminarLugar(ls)}"
value="Eliminar"
update=":LugarTabView:form_mostrar_listado:EliminarLugar"
oncomplete="LugarDialogo3.show()"> </p:commandLink>
</p:column>
</p:dataTable>
</h:panelGrid>
</p:panel>
</h:form>
</p:tab>
You are processing all form so JSF tries yo validate all components with required true. You have to tell commandLink what you want to process, for example:
<p:commandLink title="Editar" action="#{BeanLugar.editarLugar(ls)}"
value="Editar"
update=":LugarTabView:form_mostrar_listado:ModificarLugar"
oncomplete="LugarDialogo2.show()"
process="resListadoLugar"> // or the path of the component you want to process
</p:commandLink>
I want to update one component from another inside p:overlayPanel inside p:datatable
here is the code :
<p:tabView id="monpanel">
<p:tab id="tab1" title=".....">
.....
</p:tab>
<p:tab id="tab2" title=".....">
.....
</p:tab>
<p:tab id="tab3" title="Stock et fournisseurs">
<h:panelGrid>
<h:outputLabel value="Stock : "
style="text-decoration: underline;font-weight: 900;" />
<p:commandButton id="carBtn" value="Ajouter" type="button" />
<p:outputLabel id="nombref"
value="#{articlesMB.NBF} fournisseurs séléctionnés." />
<p:overlayPanel appendToBody="true" widgetVar="overlayp"
id="carPanel" for="carBtn" hideEffect="fade" dynamic="true">
<p:dataTable id="table" var="car" rowKey="#{car.fournisseurId}"
value="#{articlesMB.listfournisseurs}"
selection="#{articlesMB.selectedFournisseurs}" rows="10"
paginator="true">
<p:column selectionMode="multiple" style="width:20px" />
<p:column headerText="Id">
<h:outputText value="#{car.fournisseurId}" />
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{car.personne.nom}" />
</p:column>
<f:facet name="footer">
<p:commandButton id="multiViewButton" value="View"
icon="ui-icon-search" update=":nombref"
oncomplete="multiCarDialog.show()" />
</f:facet>
</p:dataTable>
</p:overlayPanel>
</p:tab>
<p:tabview>
I tested update=":nombref" and update="monpanel:nombref" and update=":monpanel:nombref" but always I have this error :
com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit
GRAVE: javax.faces.FacesException: Cannot find component with identifier ":nombref" referenced from "monpanel:table:multiViewButton".
How can I fix this error?
i have checkbox column in datatable, i want to have some ajax code which when i click on the checbox button on the header should check all the checkbox in the rendered data rows of the datatable. I am using primefaces, they have something out of box for this but we don't want to implement it. Please let me know if there is a easy solution using ajax.
As of now we have coded as below but we can go something better than that.
<p:dataTable id="userListTable" value="#{Bean.List}"
var="user" rowClasses="odd even"
<p:column style="width:18px">
<f:facet name="header">
<p:selectBooleanCheckbox
valueChangeListener="#{Controller.toggleCheckBox}"
partialSubmit="true" immediate="true" />
</f:facet>
<p:selectBooleanCheckbox value="#{user.disable}"
disabled="#{user.disable}"
valueChangeListener="#{circleController.enableDisableOkbutton}"
partialSubmit="true" immediate="true" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{labels['circle.userList.name']}" />
</f:facet>
<p:panelGrid styleClass="noBorders">
<p:row>
<p:column rowspan="3" style="width:60px;">
<p:graphicImage
value="#{name}.jpg"
style="width:50px;height:50px" />
</p:column>
<p:column>
<h:outputText value=" " />
<h:outputText value="#{user.firstName}" />
<h:outputText value=" " />
<h:outputText value="#{user.lastName}" />
</p:column>
</p:row>
<p:row>
<h:outputText value="#{user.country}" />
</p:row>
</p:panelGrid>
</p:column>
</p:dataTable>