org.omnifaces.taghandler
Class ValidateUniqueColumn

java.lang.Object
  extended by javax.faces.view.facelets.TagHandler
      extended by org.omnifaces.taghandler.ValidateUniqueColumn
All Implemented Interfaces:
java.util.EventListener, javax.faces.event.FacesListener, javax.faces.event.ValueChangeListener, javax.faces.view.facelets.FaceletHandler

public class ValidateUniqueColumn
extends javax.faces.view.facelets.TagHandler
implements javax.faces.event.ValueChangeListener

ValidateUniqueColumn validates if the given UIInput component in an UIData component has an unique value throughout all rows, also those not visible by pagination. This validator works directly on the data model and may therefore not work as expected if the data model does not represent all available rows of the UIData component (e.g. when there's means of lazy loading).

The default message is

{0}: Please fill out an unique value for the entire column. Duplicate found in row {1}

Usage example:

 <h:dataTable value="#{bean.items}" var="item">
   <h:column>
     <h:inputText value="#{item.value}">
       <o:validateUniqueColumn />
     </h:inputText>
   </h:column>
 </h:dataTable>
 

In an invalidating case, only the first row on which the value is actually changed (i.e. the value change event has been fired on the input component in the particular row) will be marked invalid and a faces message will be added on the client ID of the input component in the particular row. The default message can be changed by the message attribute. Any "{0}" placeholder in the message will be substituted with the label of the input component. Any "{1}" placeholder in the message will be substituted with the 1-based row index of the data model. Note that this does not take pagination into account and that this needs if necessary to be taken care of in the custom message yourself.

 <o:validateUniqueColumn message="Duplicate value!" />
 

Since:
1.3
Author:
Bauke Scholtz

Field Summary
 
Fields inherited from class javax.faces.view.facelets.TagHandler
nextHandler, tag, tagId
 
Constructor Summary
ValidateUniqueColumn(javax.faces.view.facelets.TagConfig config)
          The tag constructor.
 
Method Summary
 void apply(javax.faces.view.facelets.FaceletContext context, javax.faces.component.UIComponent parent)
          If the component is new, check if it's an instance of UIInput and then register this tag as a value change listener on it.
 java.lang.String getMessage()
          Returns the runtime evaluated value of the message attribute.
 boolean isDisabled()
          Returns the runtime evaluated value of the disabled attribute.
 void processValueChange(javax.faces.event.ValueChangeEvent event)
          When this tag is not disabled, the input value is changed, the input component is valid and the input component's local value is not null, then check for a duplicate value by visiting all rows of the parent UIData component.
 
Methods inherited from class javax.faces.view.facelets.TagHandler
getAttribute, getRequiredAttribute, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValidateUniqueColumn

public ValidateUniqueColumn(javax.faces.view.facelets.TagConfig config)
The tag constructor.

Parameters:
config - The tag config.
Method Detail

apply

public void apply(javax.faces.view.facelets.FaceletContext context,
                  javax.faces.component.UIComponent parent)
           throws java.io.IOException
If the component is new, check if it's an instance of UIInput and then register this tag as a value change listener on it. If the component is not new, check if there's an UIData parent.

Specified by:
apply in interface javax.faces.view.facelets.FaceletHandler
Throws:
java.io.IOException

processValueChange

public void processValueChange(javax.faces.event.ValueChangeEvent event)
                        throws javax.faces.event.AbortProcessingException
When this tag is not disabled, the input value is changed, the input component is valid and the input component's local value is not null, then check for a duplicate value by visiting all rows of the parent UIData component.

Specified by:
processValueChange in interface javax.faces.event.ValueChangeListener
Throws:
javax.faces.event.AbortProcessingException

getMessage

public java.lang.String getMessage()
Returns the runtime evaluated value of the message attribute.

Returns:
The runtime evaluated value of the message attribute.

isDisabled

public boolean isDisabled()
Returns the runtime evaluated value of the disabled attribute.

Returns:
The runtime evaluated value of the disabled attribute.