如何在完成成功的表单提交后才能显示对话框 [英] How to display dialog only on complete of a successful form submit
问题描述
< p:commandButton id =showDialogButtonvalue =Enregistrer
action =#{DEQbean.Ajouter()}update =@ form
oncomplete =dialogaboutDEQ.show()/>
< p:dialog id =reamrquesDEQwidgetVar =dialogaboutDEQheader =Informations
width =400closable =falseresizable =falseshowEffect =剪辑
hideEffect =clipmodal =trueappendToBody =true>
< p:message id =messagesshowDetail =trueautoUpdate =true/>
< p:commandButton value =OKaction =DEQlist/>
< / p:dialog>
只有当验证已经通过并且执行了action方法时,我才想显示对话框。然而,当所需的输入字段为空并且因此不执行操作方法时,仍然显示对话框。
只有完成成功的表单提交时,如何显示对话框?
PrimeFaces ajax响应将一个 args
对象放在具有 validationFailed
属性的JS范围中。您可以在 oncomplete
中检查。
< p :commandButton ... oncomplete =if(args& amp; amp;!args.validationFailed)dialogaboutDEQ.show()/>
如果您执行在操作方法中的验证而不是正常的验证器,并且您不能重做,那么您需要手动调用< a href =http://docs.oracle.com/javaee/7/api/javax/faces/context/FacesContext.html#validationFailed-- =noreferrer> FacesContext#validationFailed )
。
另见:
另一种不同的选择是使用< a href =http://www.primefaces.org/docs/api/3.5/org/primefaces/context/RequestContext.html#execute%28java.lang.String%29 =noreferrer> 的RequestContext#执行()
内部动作方法以编程方式指示PrimeFaces执行给定的JS代码。所以,而不是 oncomplete
,您也可以在操作方法中执行此操作:
<$ c 。$ C> RequestContext.getCurrentInstance()执行( dialogaboutDEQ.show());
如果验证失败,那么操作方法不会被调用,这样也不会被执行。
另请参见:
是使用对话框的可见
属性。您的命令按钮显然是更新包括对话框在内的整个表单(即使该对话框本身严重声明为 appendToBody =true
,这将导致它不在内父表格,即它必须有 appendToBody =false
或有自己的表单,但是ala)。你可以检查一下在 FacesContext#isPostback()
和 FacesContext#isValidationFailed()
如果执行成功的回发:
< p:dialog ... visible =#{facesContext.postback而不是facesContext.validationFailed}>
另请参见:
I have a form with 2 required input fields and a command button which shows a dialog:
<p:commandButton id="showDialogButton" value="Enregistrer"
action="#{DEQbean.Ajouter()}" update="@form"
oncomplete="dialogaboutDEQ.show()" />
<p:dialog id="reamrquesDEQ" widgetVar="dialogaboutDEQ" header="Informations"
width="400" closable="false" resizable="false" showEffect="clip"
hideEffect="clip" modal="true" appendToBody="true">
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
<p:commandButton value="OK" action="DEQlist" />
</p:dialog>
I would like to show the dialog only when the validation has passed and the action method is executed. However, when the required input fields are empty and the action method is thus not executed, the dialog is still shown.
How do I display the dialog only on complete of a successful form submit?
The PrimeFaces ajax response puts an args
object in the JS scope which has a validationFailed
property. You could just check for that in the oncomplete
.
<p:commandButton ... oncomplete="if (args && !args.validationFailed) dialogaboutDEQ.show()" />
If you're performing validation in action method instead of in a normal validator, and you can't rework that, then you need to manually call FacesContext#validationFailed()
.
See also:
A different alternative is to use RequestContext#execute()
inside action method to programmatically instruct PrimeFaces to execute the given piece of JS code. So, instead of the oncomplete
, you could also do this in action method:
RequestContext.getCurrentInstance().execute("dialogaboutDEQ.show()");
If the validation fails, then the action method is not invoked and then this would also not be executed.
See also:
Again a different alternative is to use the dialog's visible
attribute. Your command button is apparently updating the whole form including the dialog (even though the dialog is at its own badly declared with appendToBody="true"
which would cause it to not be inside the parent form anymore; i.e. it must have appendToBody="false"
or have its own form, but ala). You could check e.g. on FacesContext#isPostback()
and FacesContext#isValidationFailed()
if a successful postback is performed:
<p:dialog ... visible="#{facesContext.postback and not facesContext.validationFailed}">
See also:
- Difference between rendered and visible attributes of <p:dialog>
- How to show a popup in primefaces with the requiredMessages, only if these messages exist?
这篇关于如何在完成成功的表单提交后才能显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!