开发者

Primefaces Dialog Window - Validation closes dialog

I have an input form on a primefaces dialog and I have server side validation that checks the input fields when the user clicks a

<p:commandButton ajax="false" action="#{bean.validate}"/>.

At the end of my validate I return null as to stay on the same page but since this is 开发者_StackOverflowa dialog it closes. Is there any way to keep the dialog open when there are validation issues and close when there is not?


Didn't try it myself, but you could toggle the dialog's visibility depending on the existence of validation messages:

<p:dialog visible=”#{not empty facesContext.messages}” ...>


I am a Richfaces user, and their modalPanel (the equivalent of <p:dialog> offers a showWhenRendered attribute that could be helpful in your case.

Unfortunately, the <p:dialog> does not seems to have such feature. What you can do, is to play with some JavaScript functions.

First, keep a flag (a boolean property, initialized to false) in a bean that indicate if there were validation errors or not. Let's call this flag myBean.validationError.

Now, in your page, you can add a JavaScript code that will check for this property and eventually display the dialog box. Something like that (put it at the end of the page, or at least after the dialog declaration):

<script type="text/javascript">
    if (#{myBean.validationError}) {
        // showDialog();
        myDialog.show();
    }
</script>

So in your use case, the page will be redisplay, and because there was validation errors, the flag is set to true. Then, the if statement is evaluated and will display the dialog to the user.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜