0

I'm trying to use #{facesContext.validationFailed} to know whether the validation is failed or not, and to or not to showup the dialog.

I build a tiny project to test it but get

ReferenceError: facesContext is not defined

in my firebug, and the dialog is never shown no matter validation is failed or not.

Here's my code:

<h:form>
        <p:messages id="messages" /> 

        <h:outputLabel for="test" value="Test : *" />  
        <p:inputText value="#{newBusinessCtrl.testStr}" required="true" id="test"/>
        <p:message for="test" />  

        <p:commandButton value="Save" onclick="if (!facesContext.validationFailed)testDlg.show();"/> 
        <p:confirmDialog message="test Msg"
                         header="Success" severity="alert"            
                         widgetVar="testDlg">
            <h:outputText value="input success!"/>
        </p:confirmDialog>
</h:form>

Anyone knows why? Thanks in advance.

nosnhoj
  • 793
  • 1
  • 12
  • 30

1 Answers1

2

facesContext.validationFailed needs to be in a EL expression, i.e. #{facesContext.validationFailed}; otherwise it is a javascript variable.

However, I think that still won't give you the desired effect as the onclick script would be executed before submitting the form.

asdf
  • 36
  • 1
  • How can I forgot that! Sorry for being late to response and thank you. – nosnhoj Dec 30 '13 at 01:24
  • I changed `onclick` to `oncomplete` but the issue remains. – nosnhoj Dec 30 '13 at 01:25
  • Just found the answer before posting. All I have to do is using `visible` attribute of `p:dialog`(which also exists in `p:confirmDialog` as I found) like [here](http://forum.primefaces.org/viewtopic.php?f=3&t=16769) and [here](http://stackoverflow.com/questions/12460572/automatically-show-validation-messages-in-pdialog-on-validation-failure) said. – nosnhoj Dec 30 '13 at 01:40