Reputation: 2952
I am developing a simple page using PrimeFaces that list informations about some projects. I wanted to add a button that open a dialog with detailed information. The code is quite simple. However it doesn't work:
<h:form id="projectForm">
<p:dataTable id="projectDataTable" var="project" value="#{projectMB.projects}" >
<p:column sortBy="name" headerText="Name">
<h:outputText value="#{project.name}" />
</p:column>
<p:column sortBy="status" headerText="Status">
<h:outputText value="#{project.status}" />
<h:outputText value=" (#{project.progress}%)" />
</p:column>
<p:column style="width:4%">
<p:commandButton update=":projectForm:display" id="selectButton" oncomplete="PF('projectDialog').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{project}" target="#{projectMB.selectedProject}" />
</p:commandButton>
</p:column>
</p:dataTable>
<center>
<p:commandButton id="refreshProjectsButton" actionListener="#{projectMB.refreshProjectList}" icon="ui-icon-refresh" update="projectDataTable"/>
</center>
<p:dialog header="Project Detail" widgetVar="projectDialog" resizable="false" id="projectDlg" showEffect="fade" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">
<h:outputText value="Name:" />
<h:outputText value="#{projectMB.selectedProject.name}" style="font-weight:bold"/>
<h:outputText value="Description:" />
<h:outputText value="#{projectMB.selectedProject}" style="font-weight:bold"/>
</h:panelGrid>
</p:dialog>
</h:form>
I found a solution by adding extra form which enclose dialog
:
<h:form id="projectForm">
<p:dataTable id="projectDataTable" var="project" value="#{projectMB.projects}" >
<p:column sortBy="name" headerText="Name">
<h:outputText value="#{project.name}" />
</p:column>
<p:column sortBy="status" headerText="Status">
<h:outputText value="#{project.status}" />
<h:outputText value=" (#{project.progress}%)" />
</p:column>
<p:column style="width:4%">
<p:commandButton update=":projectForm2:display" id="selectButton" oncomplete="PF('projectDialog').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{project}" target="#{projectMB.selectedProject}" />
</p:commandButton>
</p:column>
</p:dataTable>
<center>
<p:commandButton id="refreshProjectsButton" actionListener="#{projectMB.refreshProjectList}" icon="ui-icon-refresh" update="projectDataTable"/>
</center>
</h:form>
<h:form id="projectForm2">
<p:dialog header="Project Detail" widgetVar="projectDialog" resizable="false" id="projectDlg" showEffect="fade" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">
<h:outputText value="Name:" />
<h:outputText value="#{projectMB.selectedProject.name}" style="font-weight:bold"/>
<h:outputText value="Description:" />
<h:outputText value="#{projectMB.selectedProject}" style="font-weight:bold"/>
</h:panelGrid>
</p:dialog>
</h:form>
My question is: why the first code doesn't work - method projectMB.refreshProjectList
that refresh the list in java bean is never called. I don't get any errors in javascript and java.
Upvotes: 1
Views: 563
Reputation: 1885
This is a pretty common issue with Dialogs inside forms, and you could easy find an answer if you search a little about this issue.
But perhaps this answer can help you further:
Proper Construct for Primefaces Dialog
Upvotes: 2