org.omnifaces.taghandler
Class Validator

java.lang.Object
  extended by javax.faces.view.facelets.TagHandler
      extended by javax.faces.view.facelets.MetaTagHandler
          extended by javax.faces.view.facelets.DelegatingMetaTagHandler
              extended by javax.faces.view.facelets.FaceletsAttachedObjectHandler
                  extended by javax.faces.view.facelets.ValidatorHandler
                      extended by org.omnifaces.taghandler.Validator
All Implemented Interfaces:
javax.faces.view.AttachedObjectHandler, javax.faces.view.EditableValueHolderAttachedObjectHandler, javax.faces.view.facelets.FaceletHandler, javax.faces.view.ValueHolderAttachedObjectHandler

public class Validator
extends javax.faces.view.facelets.ValidatorHandler

The <o:validator> basically extends the <f:validator> tag family with the possibility to evaluate the value expression in all attributes on a per request basis instead of on a per view build time basis. This allows the developer to change the attributes on a per request basis, such as the disabled attribute.

 <o:validator validatorId="someValidatorId" disabled="#{param.disableValidation}" />
 

When you specify for example the standard <f:validateLongRange> by validatorId="javax.faces.LongRange", then you'll be able to use all its attributes such as minimum and maximum as per its documentation, but then with the possibility to supply request based value expressions.

 <o:validator validatorId="javax.faces.LongRange" minimum="#{item.minimum}" maximum="#{item.maximum}" />
 

It is also possible to specify the validator message on a per-validator basis using the message attribute. Any "{0}" placeholder in the message will be substituted with the label of the referenced input component. Note that this attribute is ignored when the parent component has already validatorMessage specified.

 <o:validator validatorId="javax.faces.LongRange" minimum="#{item.minimum}" maximum="#{item.maximum}"
   message="Please enter between #{item.minimum} and #{item.maximum} characters" />
 

Author:
Bauke Scholtz

Nested Class Summary
protected static class Validator.RenderTimeValidator
          So that we can have a serializable validator.
 
Field Summary
 
Fields inherited from class javax.faces.view.facelets.DelegatingMetaTagHandler
delegateFactory
 
Fields inherited from class javax.faces.view.facelets.TagHandler
nextHandler, tag, tagId
 
Constructor Summary
Validator(javax.faces.view.facelets.ValidatorConfig config)
          The constructor.
 
Method Summary
 void apply(javax.faces.view.facelets.FaceletContext context, javax.faces.component.UIComponent parent)
          Create a Validator based on the binding and/or validatorId attributes as per the standard JSF <f:validator> implementation and collect the render time attributes.
<T> T
create(javax.faces.application.Application application, java.lang.String id)
          Create the concrete Converter or Validator.
 javax.faces.view.facelets.TagAttribute getTagAttribute(java.lang.String name)
          Just return TagHandler#getAttribute() via a public method (it's by default protected and otherwise thus unavailable inside collectRenderTimeAttributes().
protected  javax.faces.view.facelets.TagHandlerDelegate getTagHandlerDelegate()
           
 boolean isDisabled(javax.faces.view.facelets.FaceletContext context)
           
 
Methods inherited from class javax.faces.view.facelets.ValidatorHandler
getValidatorConfig, getValidatorId
 
Methods inherited from class javax.faces.view.facelets.FaceletsAttachedObjectHandler
applyAttachedObject, getAttachedObjectHandlerHelper, getFor
 
Methods inherited from class javax.faces.view.facelets.DelegatingMetaTagHandler
applyNextHandler, createMetaRuleset, getBinding, getTag, getTagId, setAttributes
 
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
 
Methods inherited from interface javax.faces.view.AttachedObjectHandler
applyAttachedObject, getFor
 

Constructor Detail

Validator

public Validator(javax.faces.view.facelets.ValidatorConfig config)
The constructor.

Parameters:
config - The validator config.
Method Detail

apply

public void apply(javax.faces.view.facelets.FaceletContext context,
                  javax.faces.component.UIComponent parent)
           throws java.io.IOException
Create a Validator based on the binding and/or validatorId attributes as per the standard JSF <f:validator> implementation and collect the render time attributes. Then create an anonymous Validator implementation which wraps the created Validator and delegates the methods to it after setting the render time attributes only and only if the disabled attribute evaluates true for the current request. Finally set the anonymous implementation on the parent component.

Specified by:
apply in interface javax.faces.view.facelets.FaceletHandler
Overrides:
apply in class javax.faces.view.facelets.DelegatingMetaTagHandler
Parameters:
context - The involved facelet context.
parent - The parent component to add the Validator to.
Throws:
java.io.IOException - If something fails at I/O level.

create

public <T> T create(javax.faces.application.Application application,
                    java.lang.String id)
Create the concrete Converter or Validator.


getTagAttribute

public javax.faces.view.facelets.TagAttribute getTagAttribute(java.lang.String name)
Just return TagHandler#getAttribute() via a public method (it's by default protected and otherwise thus unavailable inside collectRenderTimeAttributes().

Overrides:
getTagAttribute in class javax.faces.view.facelets.DelegatingMetaTagHandler

getTagHandlerDelegate

protected javax.faces.view.facelets.TagHandlerDelegate getTagHandlerDelegate()
Overrides:
getTagHandlerDelegate in class javax.faces.view.facelets.ValidatorHandler

isDisabled

public boolean isDisabled(javax.faces.view.facelets.FaceletContext context)
Overrides:
isDisabled in class javax.faces.view.facelets.DelegatingMetaTagHandler