Exemplo n.º 1
0
 @Override
 public void validateChangedObject(FacesContext context, UIComponent component, Object arg2)
     throws ValidatorException {
   String value = (String) arg2;
   if (StringUtils.isEmpty(value)) {
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.component.UIInput.REQUIRED",
             MessageFactory.getLabel(context, component)));
   }
   try {
     if (!vdtService.equalsPersistenceValue(entityClass, fieldName, id, value)) {
       if (StringUtils.isNotEmpty(message)) {
         throw new ValidatorException(Messages.createError(message));
       } else {
         throw new ValidatorException(
             MessageFactory.getMessage(
                 context,
                 "com.esoft.core.validator.AlreadyExistValidator.PERSISTENCE_VALUE",
                 MessageFactory.getLabel(context, component)));
       }
     }
   } catch (SecurityException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.NO_SUCH_FIELD",
             MessageFactory.getLabel(context, component),
             "get" + StringUtils.capitalize(fieldName)));
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.CLASS_NOT_FOUND",
             MessageFactory.getLabel(context, component),
             entityClass));
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.NO_SUCH_FIELD",
             MessageFactory.getLabel(context, component),
             "get" + StringUtils.capitalize(fieldName)));
   }
 }
Exemplo n.º 2
0
  @Override
  public void validate(FacesContext context, UIComponent component, Object value)
      throws ValidatorException {
    Date data = (Date) value;

    if (data != null && data.after(new Date())) {
      Object label = MessageFactory.getLabel(context, component);
      String descricaoErro = label + " não pode ser data futura";

      FacesMessage message =
          new FacesMessage(FacesMessage.SEVERITY_ERROR, descricaoErro, descricaoErro);
      throw new ValidatorException(message);
    }
  }