简体   繁体   English

如何在验证失败时保持弹出表单打开并在成功保存时关闭它?

[英]How to keep popup with form open on validation failure and close it on successful save?

I have a form with validations in JSF that needs to be open in popup.我在 JSF 中有一个带有验证的表单,需要在弹出窗口中打开。 When I submit the form, I am calling the bean method, the data send to the back end and if it successful then the pop up should close automatically.当我提交表单时,我正在调用 bean 方法,数据发送到后端,如果成功,则弹出窗口应自动关闭。

Data is storing successfully, what should I need to return from bean method, so that the pop up will close automatically.数据存储成功,我需要从bean方法返回什么,以便弹出窗口自动关闭。

And also, How can we get the response after submitting the form?还有,我们如何在提交表单后得到响应? Is that possible?那可能吗?

Below code can be used to keep the show/hide the popup based upon the validation:下面的代码可用于根据验证保持显示/隐藏弹出窗口:

<a4j:commandButton value="Create Quote" id="createQuote" action="#{quoteAction.createQuote}"
                               immediate="false" 
                               execute="envType country partner @this"
                               render="envType country partner"
                               oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('quoteResultPanel')}.show();}">
            </a4j:commandButton>

#{facesContext.maximumSeverity == null} will validate for any validation message(s) if this is not null then user will not be shown with the popup else user will be displayed with the popup. #{facesContext.maximumSeverity == null}将验证任何验证消息,如果这不是 null 那么用户将不会显示在弹出窗口中,否则用户将显示在弹出窗口中。 you can even use it the other way like close the popup only if there are no validation messages else keep the popup with the messages.您甚至可以以其他方式使用它,例如仅在没有验证消息时关闭弹出窗口,否则将弹出窗口与消息一起保留。

oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('quoteResultPanel')}.hide();}"

Look here Using JavaServer Faces (JSF) Popup Window Example .看这里Using JavaServer Faces (JSF) Popup Window Example Note that MyFaces Orchestra has support for multi-window applications out-of-the-box.请注意, MyFaces Orchestra支持开箱即用的多窗口应用程序。

If you're using RichFaces, you might want to consider using a Rich Modal Window instead of a normal popup.如果您使用的是 RichFaces,则可能需要考虑使用Rich Modal Window而不是普通的弹出窗口。

If your form is an <a4j:form> , you can use an <a4j:commandButton> for an ajax submit, and supply an oncomplete attribute to give it javascript to execute after successful submission.如果您的表单是<a4j:form> ,您可以使用<a4j:commandButton>进行 ajax 提交,并提供一个oncomplete属性以使其 javascript 在成功提交后执行。 This javascript can be a call to Richfaces.hideModalPanel('pnl');这个 javascript 可以调用Richfaces.hideModalPanel('pnl'); with the id of your modal as the argument.以您的模态的 id 作为参数。

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

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