Class AUniqueBeanFieldValidator<TBean,TField>

java.lang.Object
de.xima.fc.gui.common.validator.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:
  • Field Details

  • Constructor Details

    • AUniqueBeanFieldValidator

      protected AUniqueBeanFieldValidator(Class<TBean> beanClass, Class<TField> fieldClass)
  • Method Details

    • 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 boolean hasDuplicates(TBean bean, TField value, javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) throws Exception
      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.
      context - Current faces context.
      component - Component to validate.
      Throws:
      Exception
    • hasDuplicates

      @Deprecated protected boolean hasDuplicates(TBean bean, TField value) throws Exception
      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.
      Throws:
      Exception
    • 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)