kbeat
kbeat

Reputation: 149

RichFaces: partial form validation

I have a form containing several fields(name, surname, etc) and a datatable. Datatable is dedicated to store addresses into the backing bean. A person can have more than one address so I add a button as follows:

<a4j:commandButton action="#{bean.addAddressRow}" value="Add address" reRender="addresses" />

where "addresses" is the id of my datatable. I use a4j because there's no need to refresh the page.z

What I want to do is to skip the validation of the entire form except the address fields when this button is pressed. So a user can add one more address if all the previous addresses are correctly filled. The other fields should not be validated.

Is it possible to do?

Upvotes: 1

Views: 1152

Answers (1)

prageeth
prageeth

Reputation: 7395

Wrap your address table and the commandButton with <a4j:region> tags and set the attribute renderRegionOnly to true.
Look at following example. Here only the last two text boxes (txt2 and txt3) are validated when you press the first button. If you press the second button all three text boxes are validated.

<h:form>
  <h:inputText required="true" id="txt1"/>
  <rich:message for="txt1" style="color:red"/>

  <a4j:region renderRegionOnly="true">
      <h:inputText required="true" id="txt2"/>
      <rich:message for="txt2" style="color:red"/>
      <h:inputText required="true" id="txt3"/>
      <rich:message for="txt3" style="color:red"/>
      <a4j:commandButton value="Ok1" />
  </a4j:region>

  <a4j:commandButton value="Ok2" />
</h:form>

Upvotes: 1

Related Questions