-
- All Implemented Interfaces:
AttachedObjectHandler
,EditableValueHolderAttachedObjectHandler
,FaceletHandler
,ValueHolderAttachedObjectHandler
public class Validator extends ValidatorHandler
The
<o:validator>
is a taghandler that extends the standard<f:validator>
tag family with support for deferred value expressions in all attributes. In other words, the validator attributes are not evaluated anymore on a per view build time basis, but just on every access like as with UI components and bean properties. This has among others the advantage that they can be evaluated on a per-iteration basis inside an iterating component, and that they can be set on a custom validator without needing to explicitly register it in a tagfile.Usage
When you specify for example the standard
<f:validateLongRange>
byvalidatorId="jakarta.faces.LongRange"
, then you'll be able to use all its attributes such asminimum
andmaximum
as per its documentation, but then with the possibility to supply deferred value expressions.<o:validator validatorId="jakarta.faces.LongRange" minimum="#{item.minimum}" maximum="#{item.maximum}" />
The validator ID of all standard Faces validators can be found in their javadocs. First go to the javadoc of the class of interest, then go to
VALIDATOR_ID
in its field summary and finally click the Constant Field Values link to see the value.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 alreadyvalidatorMessage
specified.<o:validator validatorId="jakarta.faces.LongRange" minimum="#{item.minimum}" maximum="#{item.maximum}" message="Please enter between #{item.minimum} and #{item.maximum} characters" />
JSF 2.3 compatibility
The
<o:validator>
is currently not compatible with validators which are managed via themanaged=true
attribute set on theFacesValidator
annotation, at least not when using Mojarra. Internally, the converters are wrapped in another instance which doesn't have the needed setter methods specified. In order to get them to work with<o:validator>
, themanaged=true
attribute needs to be removed, so that OmniFacesValidatorManager
will automatically manage them.- Author:
- Bauke Scholtz
- See Also:
DeferredTagHandlerHelper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Validator.DeferredValidator
So that we can have a serializable validator.
-
Field Summary
-
Fields inherited from class jakarta.faces.view.facelets.DelegatingMetaTagHandler
delegateFactory
-
Fields inherited from class jakarta.faces.view.facelets.TagHandler
nextHandler, tag, tagId
-
-
Constructor Summary
Constructors Constructor Description Validator(ValidatorConfig config)
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(FaceletContext context, UIComponent parent)
Create aValidator
based on thebinding
and/orvalidatorId
attributes as per the standard Faces<f:validator>
implementation and collect the render time attributes.TagAttribute
getTagAttribute(String name)
protected TagHandlerDelegate
getTagHandlerDelegate()
boolean
isDisabled(FaceletContext context)
-
Methods inherited from class jakarta.faces.view.facelets.ValidatorHandler
getValidatorConfig, getValidatorId
-
Methods inherited from class jakarta.faces.view.facelets.FaceletsAttachedObjectHandler
applyAttachedObject, getAttachedObjectHandlerHelper, getFor
-
Methods inherited from class jakarta.faces.view.facelets.DelegatingMetaTagHandler
applyNextHandler, createMetaRuleset, getBinding, getTag, getTagId, setAttributes
-
Methods inherited from class jakarta.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 jakarta.faces.view.AttachedObjectHandler
applyAttachedObject, getFor
-
-
-
-
Constructor Detail
-
Validator
public Validator(ValidatorConfig config)
The constructor.- Parameters:
config
- The validator config.
-
-
Method Detail
-
apply
public void apply(FaceletContext context, UIComponent parent) throws IOException
Create aValidator
based on thebinding
and/orvalidatorId
attributes as per the standard Faces<f:validator>
implementation and collect the render time attributes. Then create an anonymousValidator
implementation which wraps the createdValidator
and delegates the methods to it after setting the render time attributes only and only if thedisabled
attribute evaluatestrue
for the current request. Finally set the anonymous implementation on the parent component.- Specified by:
apply
in interfaceFaceletHandler
- Overrides:
apply
in classDelegatingMetaTagHandler
- Parameters:
context
- The involved facelet context.parent
- The parent component to add theValidator
to.- Throws:
IOException
- If something fails at I/O level.
-
getTagAttribute
public TagAttribute getTagAttribute(String name)
- Overrides:
getTagAttribute
in classDelegatingMetaTagHandler
-
getTagHandlerDelegate
protected TagHandlerDelegate getTagHandlerDelegate()
- Overrides:
getTagHandlerDelegate
in classValidatorHandler
-
isDisabled
public boolean isDisabled(FaceletContext context)
- Overrides:
isDisabled
in classDelegatingMetaTagHandler
-
-