简体   繁体   English

JSF(PrimeFaces)页面不适用于单个表单

[英]JSF (PrimeFaces) page doesn't work with single form

I am developing a simple page using PrimeFaces that list informations about some projects. 我正在使用PrimeFaces开发一个简单的页面,其中列出了有关某些项目的信息。 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 : 我找到了解决方案,方法是添加包含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. 我的问题是:为什么第一个代码不起作用-从未调用刷新Java bean中列表的方法projectMB.refreshProjectList I don't get any errors in javascript and java. 我在javascript和Java中没有任何错误。

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 正确构造Primefaces对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM