Per H
Per H

Reputation: 1542

Check for validation errors in part of a form in JSF

I'm building a Seam application, which is basically a huge form divided into different parts, or modules. I need a way to figure out when a module is "complete", meaning all validation for the fields in that module passes. I then need to do something in the view, setting a css-class or whatever.

Something like:

<a:region id="region1">
    <s:div styleClass="#{invalid ? 'errors' : ''}">
       <h:inputText required="true" id="input1" />
       <h:inputText required="true" id="input2" />
       <h:commandButton value="Save this section" reRender="region1" />
    </s:div>
</a:region>

I figured I had two options:

However, I can't find any way to do any of them. Any ideas if this is even possible?

We're using JSF 1.2 with Seam.

Thanks.

Upvotes: 2

Views: 1892

Answers (1)

BalusC
BalusC

Reputation: 1108722

You can use UIInput#isValid() to check if a validation error has occurred on the particular input component.

<s:div styleClass="#{!input1.valid or !input2.valid ? 'errors' : ''}">
   <h:inputText binding="#{input1}" required="true" id="input1" />
   <h:inputText binding="#{input2}" required="true" id="input2" />
   <h:commandButton value="Save this section" reRender="region1" />
</s:div>

Upvotes: 4

Related Questions