Package de.xima.fc.gui.validator.name
Class AUniqueBeanFieldValidator<TBean,TField>
- java.lang.Object
-
- de.xima.fc.gui.validator.name.AUniqueBeanFieldValidator<TBean,TField>
-
- Type Parameters:
TBean
- Type of the bean owning the field.TField
- Type of the field to which the validator applies.
- All Implemented Interfaces:
Serializable
,EventListener
,javax.faces.validator.Validator
- Direct Known Subclasses:
AUniqueBeanStringFieldValidator
,AUniqueEntityFieldValidator
public abstract class AUniqueBeanFieldValidator<TBean,TField> extends Object implements javax.faces.validator.Validator, Serializable
Abstract base class for faces validators that check whether a certain field of a bean is unique amongst all existing entities (within a certain scope).- Since:
- 8.2.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ATTR_VALUE
protected Class<TBean>
beanClass
protected Class<TField>
fieldClass
-
Constructor Summary
Constructors Modifier Constructor Description protected
AUniqueBeanFieldValidator(Class<TBean> beanClass, Class<TField> fieldClass)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract TField
convertValue(Object value)
protected static javax.faces.validator.ValidatorException
createError()
protected static javax.faces.validator.ValidatorException
createError(Throwable e)
protected Object
findBean(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
Finds the entity to validate from the UI component.protected static Object
getValueExpressionBase(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
protected abstract boolean
hasDuplicates(TBean bean, TField value)
Checks if any duplicates exists for the given bean with the given field value.protected abstract boolean
hasValue(TField value)
void
validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
-
-
-
Method Detail
-
validate
public final void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value) throws javax.faces.validator.ValidatorException
- Specified by:
validate
in interfacejavax.faces.validator.Validator<TBean>
- Throws:
javax.faces.validator.ValidatorException
-
convertValue
protected abstract TField convertValue(@Nonnull Object value)
- Parameters:
value
- Value as received from the UI.- Returns:
- The value, converted to the expected type.
-
findBean
protected Object findBean(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
Finds the entity to validate from the UI component. The default implementation attempts to read the entity from the value expression base (e.g. when you usemyBean.selected.name
).- Parameters:
context
- Current faces context.component
- Component to validate.- Returns:
- The entity with a field to validate.
-
hasDuplicates
protected abstract boolean hasDuplicates(TBean bean, TField value)
Checks if any duplicates exists for the given bean with the given field value.- Parameters:
bean
- Bean to check for existing duplicates.value
- Field value to check for duplicates.
-
hasValue
protected abstract boolean hasValue(@Nonnull TField value)
- Parameters:
value
- The converted field value.- Returns:
true
if the value is non-empty, orfalse
otherwise. When empty, this validator is skipped.
-
createError
protected static javax.faces.validator.ValidatorException createError() throws javax.faces.validator.ValidatorException
- Throws:
javax.faces.validator.ValidatorException
-
createError
protected static javax.faces.validator.ValidatorException createError(Throwable e) throws javax.faces.validator.ValidatorException
- Throws:
javax.faces.validator.ValidatorException
-
getValueExpressionBase
protected static Object getValueExpressionBase(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
-
-