Class 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
    • Constructor Detail

      • AUniqueBeanFieldValidator

        protected AUniqueBeanFieldValidator​(Class<TBean> beanClass,
                                            Class<TField> fieldClass)
    • 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 interface javax.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 use myBean.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, or false 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)