Package javax.faces.validator

Examples of javax.faces.validator.ValidatorException


  public void customValidator(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    if (value == null) {
      return;
    }
    if (!"tobago".equalsIgnoreCase(value.toString())) {
      throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please type in 'Tobago'",
          "Please type in 'Tobago'"));
    }
  }
View Full Code Here


    String phoneNumber = (String) value;
    if (phoneNumber == null || phoneNumber.length() == 0) {
      return;
    }
    if (!phoneNumber.matches("\\+?[0-9 ]*(\\([0-9 ]*\\))?[0-9 ]*")) {
      throw new ValidatorException(MessageUtils.createErrorMessage(
          "validatorPhone", context));
    }
  }
View Full Code Here

      throws ValidatorException {
    EmailAddress emailAddress = (EmailAddress) value;

    Matcher matcher = LOCAL_PART_PATTERN.matcher(emailAddress.getLocalPart());
    if (!matcher.matches()) {
      throw new ValidatorException(MessageUtils.createErrorMessage(
          "validatorEmailLocalPart", facesContext));
    }

    matcher = DOMAIN_PATTERN.matcher(emailAddress.getDomain());
    if (!matcher.matches()) {
      throw new ValidatorException(MessageUtils.createErrorMessage(
          "validatorEmailDomain", facesContext));
    }
  }
View Full Code Here

    String phoneNumber = (String) value;
    if (phoneNumber == null || phoneNumber.length() == 0) {
      return;
    }
    if (!phoneNumber.matches("\\+?[0-9 ]*(\\([0-9 ]*\\))?[0-9 ]*")) {
      throw new ValidatorException(MessageUtils.createErrorMessage(
          "validatorPhone", context));
    }
  }
View Full Code Here

      FileItem file = (FileItem) value;
      if (maxSize != null && file.getSize() > maxSize) {
        FacesMessage facesMessage = MessageUtils.getMessage(
            facesContext, facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR,
            SIZE_LIMIT_MESSAGE_ID, maxSize, component.getId());
        throw new ValidatorException(facesMessage);
      }
      // Check only a valid file
      if (file.getSize() > 0 && contentType != null && contentType.length > 0) {
        boolean found = false;
        for (String contentTypeStr : contentType) {
          if (ContentType.valueOf(contentTypeStr).match(ContentType.valueOf(file.getContentType()))) {
            found = true;
            break;
          }
        }
        if (!found) {
          String message;
          if (contentType.length == 1) {
            message = contentType[0];
          } else {
            message = Arrays.toString(contentType);
          }
          FacesMessage facesMessage = MessageUtils.getMessage(
              facesContext, facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR,
              CONTENT_TYPE_MESSAGE_ID, message, component.getId());
          throw new ValidatorException(facesMessage);
        }
      }
    }
  }
View Full Code Here

      String submittedValue = ((EditableValueHolder) uiComponent).getSubmittedValue().toString();
      if (maximum != null && submittedValue.length() > maximum) {
        Object[] args = {maximum, uiComponent.getId()};
        FacesMessage facesMessage = MessageUtils.getMessage(facesContext,
            facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR, MAXIMUM_MESSAGE_ID, args);
        throw new ValidatorException(facesMessage);
      }
      if (minimum != null && submittedValue.length() < minimum) {
        Object[] args = {minimum, uiComponent.getId()};
        FacesMessage facesMessage = MessageUtils.getMessage(facesContext,
            facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR, MINIMUM_MESSAGE_ID, args);
        throw new ValidatorException(facesMessage);
      }
    }
  }
View Full Code Here

        catch (EvaluationException ee)
        {
          Throwable cause = ee.getCause();
          if (cause instanceof ValidatorException)
          {
            ValidatorException ve = (ValidatorException) cause;

            // If the validator throws an exception, we're
            // invalid, and we need to add a message
            setValid(false);
            FacesMessage message = ve.getFacesMessage();
            if (message != null)
            {
              message.setSeverity(FacesMessage.SEVERITY_ERROR);
              message = _wrapMessage(message);
              context.addMessage(getClientId(context), message);
View Full Code Here

          validator.invoke(context,
              new Object[] { context, this, newValue});
        }
        catch (EvaluationException ee) {
          if (ee.getCause() instanceof ValidatorException) {
            ValidatorException ve =
              (ValidatorException) ee.getCause();

            // If the validator throws an exception, we're
            // invalid, and we need to add a message
            setValid(false);
            FacesMessage message = ve.getFacesMessage();
            if (message != null) {
              message.setSeverity(FacesMessage.SEVERITY_ERROR);
              context.addMessage(getClientId(context), message);
            }
          } else {
View Full Code Here

        validator.invoke(context,
            new Object[] { context, this, newValue});
      }
      catch (EvaluationException ee) {
        if (ee.getCause() instanceof ValidatorException) {
          ValidatorException ve =
            (ValidatorException) ee.getCause();

          // If the validator throws an exception, we're
          // invalid, and we need to add a message
          setValid(false);
          FacesMessage message = ve.getFacesMessage();
          if (message != null) {
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(getClientId(context), message);
          }
        } else {
View Full Code Here

      int param = Integer.parseInt(value.toString());
   
      // validate param
      if (param > this.max || param < this.min) {
          FacesMessage msg = new FacesMessage("Guess must be between "+this.min+" and "+this.max);
          throw new ValidatorException(msg);
      }
    } catch (NumberFormatException e) {
      FacesMessage msg = new FacesMessage("Must be a number");
      throw new ValidatorException(msg);
    }
  }
View Full Code Here

TOP

Related Classes of javax.faces.validator.ValidatorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.