Uploaded image for project: 'Seam Faces'
  1. Seam Faces
  2. SEAMFACES-24

Provide convenience classes for Validators/Converters

    Details

      Description

      Provide generic abstract classes implementing Validator and Converter, for convenient removal of typecasting. Work will need to be done to figure out how to best handle ClassCastExceptions in the case when the provided value argument is not of the type required.

      --------------------------------------------------------------------------------------------------------------------------------------
      public abstract class Converter<T> implements javax.faces.convert.Converter
      {
      FacesContext context;

      public abstract T toObject(UIComponent comp, String value);

      public abstract String toString(UIComponent comp, T value);

      @Override
      public Object getAsObject(final FacesContext context, final UIComponent comp, final String value)

      { this.context = context; return toObject(comp, value); }

      @Override
      @SuppressWarnings("unchecked")
      public String getAsString(final FacesContext context, final UIComponent comp, final Object value)

      { this.context = context; return toString(comp, (T) value); }

      public FacesContext getContext()

      { return context; }
      }
      ---------------------------------------------------------------------------------------------------------------------------------------
      public abstract class Validator<T> implements javax.faces.validator.Validator
      {
      FacesContext context;

      public abstract void validate(UIComponent component, T value) throws ValidatorException;

      @Override
      @SuppressWarnings("unchecked")
      public void validate(final FacesContext context, final UIComponent component, final Object value) throws javax.faces.validator.ValidatorException
      { this.context = context; validate(component, (T) value); }

      public FacesContext getContext()
      { return context; }

      }
      ---------------------------------------------------------------------------------------------------------------------------------------
      Provide extension of ValidatorException to remove need for creating new FacesMessage objects when throwing ValidatorExceptions from Validators.

      public class ValidatorException extends javax.faces.validator.ValidatorException
      {
      public ValidatorException(final String message)

      { super(new FacesMessage(message)); }

      }

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bleathem Brian Leathem
                Reporter:
                lincolnthree Lincoln Baxter III
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: