@Override
  public void validate(final FacesContext context) {
    context
        .getApplication()
        .publishEvent(context, PreValidateEvent.class, UIValidateForm.class, this);
    BeanManager manager = BeanManagerAccessor.getBeanManager();
    manager.fireEvent(this, BEFORE);

    Validator validator = context.getApplication().createValidator(validatorId);
    if (validator == null) {
      throw new IllegalArgumentException(
          "Could not create Validator with id: [" + validatorId + "]");
    }

    try {
      UIComponent parent = this.getParent();
      validator.validate(context, parent, components);
    } catch (ValidatorException e) {
      setValid(false);
      for (UIInput comp : components.values()) {
        comp.setValid(false);
        // TODO Put this back when attributes can control it
        // context.addMessage(comp.getClientId(), e.getFacesMessage());
      }
      context.addMessage(null, e.getFacesMessage());
    }

    manager.fireEvent(this, AFTER);
    context
        .getApplication()
        .publishEvent(context, PostValidateEvent.class, UIValidateForm.class, this);
  }
Exemple #2
0
  public void validatePartialCredit(FacesContext context, UIComponent toValidate, Object value) {
    Integer pCredit = null;
    boolean isValid = true;
    if ("0.0".equals(value.toString())) {
      pCredit = 0;
    } else {
      try {
        pCredit = Integer.parseInt(value.toString());
      } catch (NumberFormatException e) {
        isValid = false;
      }
    }

    if (isValid && (pCredit == null || pCredit < 0 || pCredit > 99)) {
      isValid = false;
    }

    if (!isValid) {
      ((UIInput) toValidate).setValid(false);
      FacesMessage message = new FacesMessage();
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      String summary =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
              "partial_credit_limit_summary");
      String detail =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
              "partial_credit_limit_detail");
      message.setSummary(summary);
      message.setDetail(detail);
      context.addMessage(toValidate.getClientId(context), message);
    }
  }
  /** Validate if password and confirm password field is equals */
  @Override
  public void validate(FacesContext context, UIComponent component, Object value) {

    String password = value.toString();

    UIInput uiInputConfirmPassword = (UIInput) component.getAttributes().get("confirmPassword");
    String confirmPassword = uiInputConfirmPassword.getSubmittedValue().toString();

    // Password and confirmPassword are required
    if (password == null
        || password.isEmpty()
        || confirmPassword == null
        || confirmPassword.isEmpty()) {
      return;
    }

    // If password and confirmPassword aren´t equal
    if (!password.equals(confirmPassword)) {
      uiInputConfirmPassword.setValid(false);
      FacesMessage msg =
          guiUtils.getFacesMessage(
              context, FacesMessage.SEVERITY_ERROR, "edit.user.passwordNotEqual");
      throw new ValidatorException(msg);
    }
  }
Exemple #4
0
  public void validateCaptcha(FacesContext context, UIComponent toValidate, Object value) {

    if (c != null) {
      Map map = context.getExternalContext().getRequestParameterMap();
      String challenge = map.get("recaptcha_challenge_field").toString();
      String response = map.get("recaptcha_response_field").toString();
      HttpServletRequest req =
          (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
      ReCaptchaResponse resp = r.checkAnswer(req.getRemoteAddr(), challenge, response);
      if (!resp.isValid() || hasValidationErrors) {
        Logger.getLogger(ContactUsPage.class.getName())
            .info("INVALID RESPONSE: " + resp.getErrorMessage());
        ((UIInput) toValidate).setValid(false);
        if (hasValidationErrors) {
          context.addMessage(
              toValidate.getClientId(context),
              new FacesMessage(
                  "Some required information was entered incorrectly. Please press refresh below to get a new challenge, then correct the issue."));
          hasValidationErrors = false;
        } else {
          context.addMessage(
              toValidate.getClientId(context),
              new FacesMessage("Press refresh below to get a new challenge."));
          hasValidationErrors = false;
        }
      }
    }
  }
 public void validateEmail(FacesContext context, UIComponent toValidate, Object value) {
   String email = (String) value;
   if (email.indexOf('@') == -1) {
     ((UIInput) toValidate).setValid(false);
     FacesMessage message = new FacesMessage("Invalid Email");
     context.addMessage(toValidate.getClientId(context), message);
   }
 }
Exemple #6
0
 public void validateSubject(FacesContext context, UIComponent toValidate, Object value) {
   String subject = (String) value;
   if (subject.indexOf("Select a subject") != -1) {
     ((UIInput) toValidate).setValid(false);
     FacesMessage message = new FacesMessage("Please select a subject.");
     context.addMessage(toValidate.getClientId(context), message);
     hasValidationErrors = true;
   }
 }
Exemple #7
0
 public void validateShortDescription(FacesContext context, UIComponent toValidate, Object value) {
   String newValue = (String) value;
   if (newValue != null && newValue.trim().length() > 0) {
     if (newValue.length() > 255) {
       ((UIInput) toValidate).setValid(false);
       FacesMessage message =
           new FacesMessage("The field cannot be more than 255 characters in length.");
       context.addMessage(toValidate.getClientId(context), message);
     }
   }
   if ((newValue == null || newValue.trim().length() == 0)
       && getVDCRequestBean().getCurrentVdcNetwork().isRequireDVdescription()) {
     FacesMessage message = new FacesMessage("The field must have a value.");
     context.addMessage(toValidate.getClientId(context), message);
     ((UIInput) toValidate).setValid(false);
     context.renderResponse();
   }
 }
Exemple #8
0
 public void validateIsEmpty(FacesContext context, UIComponent toValidate, Object value) {
   String newValue = (String) value;
   if (newValue == null || newValue.trim().length() == 0) {
     ((UIInput) toValidate).setValid(false);
     FacesMessage message = new FacesMessage("The field must have a value.");
     context.addMessage(toValidate.getClientId(context), message);
     context.renderResponse();
   }
 }
  @SuppressWarnings({"UnusedParameters"})
  public void validateLogin(FacesContext context, UIComponent toValidate, Object login) {
    String loginStr = (String) login;
    UIInput valInput = (UIInput) toValidate;

    if (loginStr.trim().length() == 0) {
      FacesUtil.messageError("login", "Небходимо ввести имя пользователя.", null);
      valInput.setValid(false);
    } else if (!usersService.isLoginRegistered(loginStr)) {
      FacesUtil.messageError(
          "login", "Пользователь " + login + " не зарегистрирован в системе", null);
      valInput.setValid(false);
    }

    if (!valInput.isValid()) {
      effect.setFired(false);
    }
  }
Exemple #10
0
 public void validatePhoneOrEmail(FacesContext ctx, UIComponent toValidate, Object value) {
   if (value != null
       && parsePhone(value.toString()) == null
       && parseEmail(value.toString()) == null) {
     ((UIInput) toValidate).setValid(false);
     ctx.addMessage(
         toValidate.getClientId(ctx),
         Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.phoneOrEmail.malformed"));
   }
 }
Exemple #11
0
 public void validateUsername(FacesContext ctx, UIComponent toValidate, Object value) {
   if (!currentPlayer.getName().equals(value)) {
     String username = value.toString();
     try {
       new MessageFormat(Bundles.Common.message("reg.newbie.login")).parse(username);
       ((UIInput) toValidate).setValid(false);
       ctx.addMessage(
           toValidate.getClientId(ctx),
           Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.username.reserved"));
     } catch (ParseException e) {
       if (cem.findByAttribute(Player_.name, username) != null) {
         ((UIInput) toValidate).setValid(false);
         ctx.addMessage(
             toValidate.getClientId(ctx),
             Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.username.occupied"));
       }
     }
   }
 }
 public void validatePassword(FacesContext context, UIComponent toValidate, Object value) {
   String confirmPassword = (String) value;
   String password =
       (String) toValidate.getParent().findComponent("password").getAttributes().get("value");
   if (!confirmPassword.equals(password)) {
     ((UIInput) toValidate).setValid(false);
     FacesMessage message = new FacesMessage("Passwords don't match");
     context.addMessage(toValidate.getClientId(context), message);
   }
 }
Exemple #13
0
 public void validateIsEmptyRequiredAffiliation(
     FacesContext context, UIComponent toValidate, Object value) {
   String newValue = (String) value;
   if ((newValue == null || newValue.trim().length() == 0)
       && getVDCRequestBean().getCurrentVdcNetwork().isRequireDVaffiliation()) {
     FacesMessage message = new FacesMessage("The field must have a value.");
     context.addMessage(toValidate.getClientId(context), message);
     context.renderResponse();
     ((UIInput) toValidate).setValid(false);
   }
 }
  public void validate(FacesContext context, UIComponent toValidate, Object value) {
    String dateString = ((String) value).trim();
    boolean valid = validate(dateString);
    if (!valid) {
      ((UIInput) toValidate).setValid(false);

      FacesMessage message =
          new FacesMessage(
              "Invalid Date Format.  Valid formats are YYYY-MM-DD, YYYY-MM, or YYYY. Optionally, 'BC' can be appended to the year. (By default, AD is assumed.)");
      context.addMessage(toValidate.getClientId(context), message);
    }
  }
Exemple #15
0
 // checks if the user name is still available
 // if not, a message will be shown indicating that the
 // user name already exists
 public void validateUserName(FacesContext context, UIComponent toValidate, Object value) {
   String userName = (String) value;
   if (!this.um.isUserNameAvailable(userName)) {
     ((UIInput) toValidate).setValid(false);
     FacesContext fc = FacesContext.getCurrentInstance();
     ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m");
     message.setText(
         bundle.getString("register_userExists"),
         bundle.getString("register_userExistsDetail"),
         FacesMessage.SEVERITY_ERROR,
         toValidate.getClientId());
   }
 }
  /**
   * Validates the "email" field of checkoutForm. If it does not follow the expected syntax, queues
   * an error message.
   */
  public void validateEmail(FacesContext context, UIComponent toValidate, Object value) {
    logger.info("validateEmail");

    String message = "";

    String email = (String) value;

    if (email.indexOf('@') == -1) {
      ((UIInput) toValidate).setValid(false);
      message =
          CoffeeBreakBean.loadErrorMessage(
              context, CoffeeBreakBean.CB_RESOURCE_BUNDLE_NAME, "EMailError");
      context.addMessage(toValidate.getClientId(context), new FacesMessage(message));
    }
  }
 public void validateLogin(FacesContext context, UIComponent toValidate, Object value) {
   String login = (String) value;
   try {
     if (!superUserService.validateNewLogin(login)) {
       ((UIInput) toValidate).setValid(false);
       FacesMessage message = new FacesMessage("This login already exist");
       context.addMessage(toValidate.getClientId(context), message);
     }
   } catch (DataAccessException exception) {
     message = "Database error, try again later";
   } catch (TransactionException exception) {
     message = "Database error, try again later";
   } catch (Exception e) {
     message = "Sorry, service is currently unavailable";
   }
 }
  @Override
  public void validate(FacesContext context, UIComponent component, Object value)
      throws ValidatorException {

    String password = (String) value;
    if (password.length() < 6 || password.length() > 12) {

      UIInput input = (UIInput) component;
      input.setValid(false);
      context.addMessage(
          component.getClientId(context),
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "A jelszó hossza nem megfelelő.",
              "A jelszó hossza nem megfelelő."));
    }
  }
  @Override
  public void validate(FacesContext fContext, UIComponent comp, Object obj)
      throws ValidatorException {
    String password = obj.toString();
    UIInput uiInputConfirmPassword = (UIInput) comp.getAttributes().get("confirmPassword");
    String confirmPassword = uiInputConfirmPassword.getSubmittedValue().toString();
    if (password == null
        || password.isEmpty()
        || confirmPassword == null
        || confirmPassword.isEmpty()) {
      return;
    }

    if (!password.equals(confirmPassword)) {
      uiInputConfirmPassword.setValid(false);
      throw new ValidatorException(new FacesMessage("Password must match confirm password."));
    }
  }
Exemple #20
0
  public void validateAlias(FacesContext context, UIComponent toValidate, Object value) {
    CharacterValidator charactervalidator = new CharacterValidator();
    charactervalidator.validate(context, toValidate, value);
    String alias = (String) value;

    boolean isValid = false;
    VDC vdc = vdcService.findByAlias(alias);
    if (alias.equals("") || vdc != null) {
      isValid = true;
    }

    if (isValid) {
      ((UIInput) toValidate).setValid(false);

      FacesMessage message = new FacesMessage("This alias is already taken.");
      context.addMessage(toValidate.getClientId(context), message);
    }
    resetScholarProperties();
  }
Exemple #21
0
  public void validateName(FacesContext context, UIComponent toValidate, Object value) {
    String name = (String) value;
    if (name != null && name.trim().length() == 0) {
      FacesMessage message = new FacesMessage("The dataverse name field must have a value.");
      context.addMessage(toValidate.getClientId(context), message);
      context.renderResponse();
    }
    boolean nameFound = false;
    VDC vdc = vdcService.findByName(name);
    if (vdc != null) {
      nameFound = true;
    }
    if (nameFound) {
      ((UIInput) toValidate).setValid(false);

      FacesMessage message = new FacesMessage("This name is already taken.");
      context.addMessage(toValidate.getClientId(context), message);
    }

    resetScholarProperties();
  }
  // validador
  public void validaISBN(FacesContext context, UIComponent componente, Object objeto)
      throws ValidatorException {
    // Get the component's contents and cast it to a String
    String isbnDigitado = (String) objeto;

    // Set the isbn pattern string
    Pattern p = Pattern.compile("\\d{1,2}-\\d{3,5}-\\d{3,4}-[0-9xX]{1}");

    // Match the given string with the pattern
    Matcher m = p.matcher(isbnDigitado);

    // Check whether match is found
    boolean matchFound = m.matches();

    if (!matchFound) {
      ((UIInput) componente).setValid(false);

      FacesMessage message = new FacesMessage("ISBN Inválido.");
      context.addMessage(componente.getClientId(context), message);
    }
  }
  @Override
  public void validate(FacesContext context, UIComponent component, Object value)
      throws ValidatorException {
    UIInput startDateComponent = (UIInput) component.getAttributes().get("dateStart");

    Date startDate = new Date();
    if (null != startDateComponent && null != startDateComponent.getValue()) {
      startDate = (Date) startDateComponent.getValue();
    } else {
      return;
    }
    Date endDate = new Date();
    if (null != value) {
      endDate = (Date) value;
      if (startDate.after(endDate)) {
        startDateComponent.setValid(false);
        throw new ValidatorException(
            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validate Error", "起始日期必须小于结束日期!"));
      }
    } else {
      return;
    }
  }
Exemple #24
0
 public static Object getConvertedValue(
     final FacesContext context, final UIInput component, final Object submittedValue) {
   try {
     final Renderer renderer = getRenderer(context, component);
     if (renderer != null) {
       return renderer.getConvertedValue(context, component, submittedValue);
     } else if (submittedValue instanceof String) {
       return getConvertedUIOutputValue(context, component, submittedValue);
     }
   } catch (final ConverterException e) {
     final FacesMessage facesMessage = e.getFacesMessage();
     if (facesMessage != null) {
       context.addMessage(component.getClientId(context), facesMessage);
     } else {
       final Object[] args = new Object[] {UIComponentUtil.getLabel(component)};
       context.addMessage(
           component.getClientId(context),
           FacesMessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID, args));
     }
     component.setValid(false);
   }
   return submittedValue;
 }
 protected void setInvalid(UIComponent comp) {
   if (comp instanceof UIInput) ((UIInput) comp).setValid(false);
 }