1

I have a modal window that I only want to launch when one of several forms on a page has errors. Is there a way using el to identify if a specific form has errors?

example pseudocode:

<h:form id="form1">

</h:form>

<h:form id="form2">

</h:form>

<a4j:rendered="#{form1.hasErrors()}">
    ... modal here ... 
</a4j:rendered>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Dave Maple
  • 8,102
  • 4
  • 45
  • 64

1 Answers1

6

If you have an execute="@form" in the ajax request, then you could use UIForm#isSubmitted() in combination with FacesContext#isValidationFailed().

<h:form binding="#{form1}">

</h:form>

<h:form binding="#{form2}">

</h:form>

<a4j:xxx rendered="#{form1.submitted and facesContext.validationFailed}">
    Validation of form1 has failed.
</a4j:xxx>

<a4j:xxx rendered="#{form2.submitted and facesContext.validationFailed}">
    Validation of form2 has failed.
</a4j:xxx>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Is there a way to accomplish the same with a standard form submit? – Dave Maple Jul 20 '12 at 14:19
  • Of course it'll just work for synchronous requests as well. I didn't mean to imply that it would work for ajax requests only, but that it would in case of ajax requests only work if the form itself is also included in the `execute`. It won't work if you include for example only a particular input field in the `execute` (which could be workarounded by e.g. determining the button pressed based on `#{param}`). I just assumed that you were using ajax, because you've there an `a4j` component. – BalusC Jul 20 '12 at 14:25