Package org.crank.validation

Examples of org.crank.validation.FieldValidator


     * @throws Exception
     */
    private void findAndExecuteValidationRule(PrintWriter writer, String validatorName,
            String value, String type) throws Exception {
        /* Look up the validator in the object registry. */
        FieldValidator validator = lookupValidatorInRegistry(validatorName);
        log.info("Found validator " + validator);

        /* Convert the object if the type is specified. */
        Object oValue = null;
        if (type == null || "".equals(type.trim())) {
            oValue = value;
        } else {
            oValue = convertIfNeeded(value, type);
        }

        /* Actually validated the field. */
        ValidatorMessage message = (ValidatorMessage) validator.validate(oValue, "none");
        if (!message.hasError()) {
            log.info("VALID");
            writer.print("valid");
        } else {
            log.info("NOT VALID");
View Full Code Here


     * @return
     */
    private FieldValidator lookupValidatorInRegistry(String validator) {
        ObjectRegistry applicationContext = CrankContext.getObjectRegistry();

        FieldValidator fvalidator = (FieldValidator) applicationContext.getObject(
                CrankConstants.FRAMEWORK_PREFIX + CrankConstants.FRAMEWORK_DELIM
                        + "validator" + CrankConstants.FRAMEWORK_DELIM + validator,
                FieldValidator.class);
        return fvalidator;
    }
View Full Code Here

    public void setUp() {
        //empty
    }

    public void testAreaCode()  throws Exception {
        FieldValidator validator = (FieldValidator) applicationContext.getBean("areaCode");

        validateErrorsPresent(validator, "ab", 2);
        validateErrorsPresent(validator, "777", 1);
        validateErrorsPresent(validator, "100", 1);
        validateErrorsPresent(validator, "301", 0);
View Full Code Here

        validateErrorsPresent(validator, "100", 1);
        validateErrorsPresent(validator, "301", 0);
    }

    public void testEmail()  throws Exception {
        FieldValidator validator = (FieldValidator) applicationContext.getBean("email");

        validateErrorsPresent(validator, "rick@rick.com", 0);
        validateErrorsPresent(validator, "rick.cic", 1);
        validateErrorsPresent(validator, "rick@rick", 1);
    }
View Full Code Here

        validateErrorsPresent(validator, "rick@rick", 1);
    }


    public void testReproduceJiraSRA120()  throws Exception {
        FieldValidator validator = (FieldValidator) applicationContext.getBean("address");

        validateErrorsPresent(validator, "address 123", 0);
        validateErrorsPresent(validator, "0 address", 0);
        validateErrorsPresent(validator, "123", 1);
        validateErrorsPresent(validator, "foo", 1);
View Full Code Here

    String[] fieldNameHolder = new String[] { "" };
   
    /* Find the validator. How the validator is found
     * varies amongst subclasses.
     */
    FieldValidator validator = findValidatorAndFieldName(facesContext,
        component, fieldNameHolder);

    /* Validate the field. */
    ValidatorMessageHolder message = validator.validate(
        fieldValueToValidate, fieldNameHolder[0]);

    convertMessageToFacesMessages(message, facesContext, component);
       
        cleanup();
View Full Code Here

     * Look up the crank validators and then apply the properties from the
     * validationMetaData to them.
     */
    for (ValidatorMetaData validationMetaData : validationMetaDataList) {
      /* Look up the FieldValidator. */
      FieldValidator validator = lookupValidatorInRegistry(
          validationMetaData
          .getName());
      /*
       * Apply the properties from the validationMetaData to the
       * validator.
 
View Full Code Here

   */
  private FieldValidator lookupValidatorInRegistry(
      String validationMetaDataName) {
    ObjectRegistry applicationContext = CrankContext.getObjectRegistry();

    FieldValidator validator = (FieldValidator) applicationContext
        .getObject(CrankConstants.FRAMEWORK_PREFIX
            + CrankConstants.FRAMEWORK_DELIM + "validator"
            + CrankConstants.FRAMEWORK_DELIM
            + validationMetaDataName, FieldValidator.class);
    return validator;
View Full Code Here

        /* Try to read the validator out of the Spring context.
         * First lookup with id, if you don't find it with component id, use the client id.
         */
      ObjectRegistry applicationContext = CrankContext.getObjectRegistry();
        String componentId = component.getId();
        FieldValidator validator;
       
        try {
          /* Look up the more specific validator, e.g., EmployeeForm.age. */
            String clientId = component.getClientId(facesContext);
            validator = (FieldValidator) applicationContext.getObject(clientId);
View Full Code Here

TOP

Related Classes of org.crank.validation.FieldValidator

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.