2

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:

  • Using some sort of view-logic (like #{invalid} for a single field)
  • Using a method in the bean, where I get all components for the module programmatically, and check them for validation errors.

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.

Per H
  • 1,542
  • 10
  • 19

1 Answers1

4

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Nice, that works! However, I also tried binding the components to properties in the bean, but I get a NullpointerException when doing so. Do you know anything about that? I thought it was as simple as using binding="#{myBean.input1}" and then declaring a UIInput-property in the bean.. – Per H Jul 21 '11 at 14:30