开发者

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. 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.

Data is storing successfully, what should I need to return from bean method, so that the pop up will close automatically.

And also, How can we get the response after s开发者_高级运维ubmitting 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. 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. Note that MyFaces Orchestra has support for multi-window applications out-of-the-box.


If you're using RichFaces, you might want to consider using a Rich Modal Window instead of a normal popup.

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. This javascript can be a call to Richfaces.hideModalPanel('pnl'); with the id of your modal as the argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜