Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf p:验证失败时未隐藏对话框_Jsf_Primefaces_Jsf 2 - Fatal编程技术网

Jsf p:验证失败时未隐藏对话框

Jsf p:验证失败时未隐藏对话框,jsf,primefaces,jsf-2,Jsf,Primefaces,Jsf 2,我在不关闭PrimeFaces对话框时遇到问题。输入字段“用户名”是必需的: <p:outputLabel for="username" value="Username: "/> <p:inputText id="username" value="#{employeeController.employee.username}" required="true"/> <p:dialog header="Create Employee" id="employee

我在不关闭PrimeFaces对话框时遇到问题。输入字段“用户名”是必需的:

<p:outputLabel for="username" value="Username: "/>
<p:inputText id="username"
    value="#{employeeController.employee.username}" required="true"/>
<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>
最终编辑:

<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>

我的对话框正在关闭,因为我更新了整个表单。将
update=“:employeeForm”
更改为
update=“:employeeForm:employeeTable”
使事情按预期进行。

我建议在成功保存操作后在
employeeController.doSaveEmployee()
中关闭操作

<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('myDialogVar').hide();");

不确定为什么要使用oncomplete=“args&;…”。我从来没有用过,效果很好

<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>
oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()"
我使用它的方式如下:

<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>
 oncomplete="if (!args.validationFailed) PF('employeeAddDialog').hide()"

这是一个问题错误吗

求你了。这段代码之外的“变量”太多,这可能是导致您看到的行为的原因。您可以添加EmployeeController源代码的必要部分吗?不要发布“更多代码”为ypurself创建一个,并发布我的问题是一个相对较大的spring应用程序的一部分,我不知道如何发布一个没有张贴代码墙。我使用Abihabi87提供的半工作解决方案添加了EmployeeController提供的doSaveEmployee()。谢谢,该解决方案运行良好。现在,仅当填写了必填字段时,对话框才会关闭。但是,现在出现了另一个小问题:单击“保存”后,空字段消息不再显示。我得调查一下。但主要问题已经解决了。我刚刚意识到,只有从“保存”按钮中删除update=“:employeeForm”时,解决方案才有效。这就解释了为什么消息没有出现。这更多的是一个评论而不是答案。请这样做
<p:dialog header="Create Employee" id="employeeAddDialog" widgetVar="employeeAddDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
  <p:outputPanel id="employeeDataCreate">
    <h:panelGrid columns="2">
      <p:outputLabel for="username" value="Username: " />
      <p:inputText id="username" value="#{employeeController.employee.username}" required="true" />

      <p:outputLabel for="password" value="Password: " />
      <p:password id="password" value="#{employeeController.employee.password}" />
    </h:panelGrid>
    <h:panelGrid columns="3">
      <p:commandButton value="Save" action="#{employeeController.doSaveEmployee()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('employeeAddDialog').hide()" update=":employeeForm" />
      <p:commandButton value="Abort" oncomplete="PF('employeeAddDialog').hide()" />
    </h:panelGrid>
  </p:outputPanel>
</p:dialog>