Primefaces – Skip bean validation in a datatable

Goal

We want to bypass the validations in a datatable according to the button we press

Description

We are using Primefaces and we have a table with existing lines associated to my persisted entity that may be removed from that entity and, at the bottom of that table, there is a new line that may be added to the entity. When clicking the remove option, the last line’s validations should be bypassed. When clicking the add option, however, all validations associated to the last line should be checked.

How to

<f:validateBean disabled="#{!empty param['disableValidation']}">
  <h:inputText ... /> <h:selectOne .... /> all fields that should or shouldn't be validated
</f:validateBean>

or, for a single field:

<h:inputText ...>
  <f:validateBean disabled="#{!empty param['disableValidation']}" />
</h:inputText>

and finally, pass the appropriate parameter option within the command button:

<p:commandButton action="#{bean.action}" value="click me">
  <f:param name="disableValidation" value="true" />           
</p:commandButton>

Additionally, it is possible also to specify the expression language so that the field may be or not required as appropriately set from the command button:

 <p:inputText required="#{empty param['disableValidation']}" />

Explanations

This recipe, taken from Primefaces forum shows a simple yet effective way to achieve our goal of validations within a table

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s