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