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> 

1 Answer 1

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> 
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to accomplish the same with a standard <h:commandButton /> form submit?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.