Package javax.faces.validator

Examples of javax.faces.validator.LengthValidator


     *
     * @see org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
     */
    @Override
    protected Validator createValidator() {
        LengthValidator validator = new LengthValidator();
        Map<String, Object> options = getOptions();
        if (options.containsKey(MINIMUM)) {
            validator.setMinimum((Integer) options.get(MINIMUM));
        }
        if (options.containsKey(MAXIMUM)) {
            validator.setMaximum((Integer) options.get(MAXIMUM));
        }
        return validator;
    }
View Full Code Here


            } else {
                messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use for that case ( no min/max set,
                                                                         // validator always pass ).
            }
        } else if (component instanceof LengthValidator) {
            LengthValidator validator = (LengthValidator) component;
            if (validator.getMaximum() > 0) {
                if (validator.getMinimum() > 0) {
                    messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
                } else {
                    messageId = LengthValidator.MAXIMUM_MESSAGE_ID;
                }
            } else if (validator.getMinimum() > 0) {
                messageId = LengthValidator.MINIMUM_MESSAGE_ID;
            } else {
                messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use for that case ( no min/max set,
                                                                         // validator always pass ).
            }
        } else if (component instanceof LongRangeValidator) {
            LongRangeValidator validator = (LongRangeValidator) component;
            if (validator.getMaximum() != LONG_RANGE_VALIDATOR_DEFAULTS.getMaximum()) {
                if (validator.getMinimum() != LONG_RANGE_VALIDATOR_DEFAULTS.getMinimum()) {
                    messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
                } else {
                    messageId = LongRangeValidator.MAXIMUM_MESSAGE_ID;
                }
            } else if (validator.getMinimum() != LONG_RANGE_VALIDATOR_DEFAULTS.getMinimum()) {
                messageId = LongRangeValidator.MINIMUM_MESSAGE_ID;
            } else {
                messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use for that case ( no min/max set,
                                                                         // validator always pass ).
            }
View Full Code Here

            }
            if (validator.getMinimum() > Double.MIN_VALUE) {
                descriptor.addParameter(MINIMUM, validator.getMinimum());
            }
        } else if (component instanceof LengthValidator) {
            LengthValidator validator = (LengthValidator) component;
            if (validator.getMaximum() > 0) {
                descriptor.addParameter(MAXIMUM, validator.getMaximum());
            }
            if (validator.getMinimum() > 0) {
                descriptor.addParameter(MINIMUM, validator.getMinimum());
            }
        } else if (component instanceof LongRangeValidator) {
            LongRangeValidator validator = (LongRangeValidator) component;
            if (validator.getMaximum() != 0) {
                descriptor.addParameter(MAXIMUM, validator.getMaximum());
            }
            if (validator.getMinimum() != 0) {
                descriptor.addParameter(MINIMUM, validator.getMinimum());
            }
        } else if (component instanceof RegexValidator) {
            RegexValidator validator = (RegexValidator) component;
            descriptor.addParameter(PATTERN, validator.getPattern());
        } else if (component instanceof RequiredValidator) {
            // do nothing.
        } else {
            super.fillParameters(descriptor, component);
        }
View Full Code Here

        UIInput text = (UIInput)facesContext.getViewRoot().findComponent("form2:text");
        validators = text.getValidators();
        if (validators == null || validators.length == 0)
        {
            text.addValidator(new LengthValidator(7, 3));
        }

        return "ok";
    }
View Full Code Here

    protected void processValidation(FacesContext facesContext,
            UIComponent uiComponent, MetaDataEntry metaDataEntry,
            Object convertedObject) throws ValidatorException
    {
        Length annotation = metaDataEntry.getValue(Length.class);
        LengthValidator lengthValidator = (LengthValidator)facesContext.getApplication()
                                            .createValidator("javax.faces.Length");

        lengthValidator.setMinimum(annotation.minimum());
        lengthValidator.setMaximum(annotation.maximum());

        lengthValidator.validate(facesContext, uiComponent, convertedObject);
    }
View Full Code Here

    public boolean configureTrinidadComponent(FacesContext facesContext, UIComponent uiComponent,
                                              Map<String, Object> metaData)
    {
        boolean informationAdded = false;
        //TODO
        LengthValidator lengthValidator = (LengthValidator)facesContext.getApplication()
                                            .createValidator("org.apache.myfaces.trinidad.Length");

        Object minLength = null;
        if(metaData.containsKey(CommonMetaDataKeys.MIN_LENGTH))
        {
            minLength = metaData.get(CommonMetaDataKeys.MIN_LENGTH);
        }
        else if(metaData.containsKey(CommonMetaDataKeys.MIN_LENGTH_DEFAULT))
        {
            minLength = metaData.get(CommonMetaDataKeys.MIN_LENGTH_DEFAULT);
        }

        if(minLength instanceof Integer)
        {
            lengthValidator.setMinimum((Integer)minLength);
            informationAdded = true;
        }

        Object maxLength = null;
        if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH))
        {
            maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH);
        }
        else if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH_DEFAULT))
        {
            maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH_DEFAULT);
        }

        if(maxLength instanceof Integer)
        {
            if(processComponent(uiComponent))
            {
                ReflectionUtils.tryToInvokeMethod(
                        uiComponent,
                        ReflectionUtils.tryToGetMethod(
                                uiComponent.getClass(),
                                "setMaximumLength",
                                int.class),
                        maxLength);
            }
           
            lengthValidator.setMaximum((Integer)maxLength);
            informationAdded = true;
        }

        //reInitValidators((EditableValueHolder)uiComponent, metaData); //search wrappers and call .deactivate

        if(informationAdded && lengthValidator instanceof ClientValidator)
        {
            if(uiComponent instanceof EditableValueHolder)
            {
                ((EditableValueHolder)uiComponent).addValidator(
                        new ExtValTrinidadClientValidatorWrapper((ClientValidator)lengthValidator));
            }
            else if (uiComponent instanceof CoreOutputLabel)
            {
                if(lengthValidator.getMinimum() > 0)
                {
                    ((CoreOutputLabel)uiComponent).setShowRequired(true);
                }

                if(Boolean.TRUE.equals(metaData.get(CommonMetaDataKeys.SKIP_VALIDATION)))
View Full Code Here

    protected Validator createValidator()
        throws JspException
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        setValidatorId(VALIDATOR_ID);
        LengthValidator validator = (LengthValidator)super.createValidator();
        if (_minimum != null)
        {
            if (UIComponentTag.isValueReference(_minimum))
            {
                ValueBinding vb = facesContext.getApplication().createValueBinding(_minimum);
                validator.setMinimum(ConverterUtils.convertToInt(vb.getValue(facesContext)));
            }
            else
            {
                validator.setMinimum(ConverterUtils.convertToInt(_minimum));
            }
        }
        if (_maximum != null)
        {
            if (UIComponentTag.isValueReference(_maximum))
            {
                ValueBinding vb = facesContext.getApplication().createValueBinding(_maximum);
                validator.setMaximum(ConverterUtils.convertToInt(vb.getValue(facesContext)));
            }
            else
            {
                validator.setMaximum(ConverterUtils.convertToInt(_maximum));
            }
        }
        return validator;
    }
View Full Code Here

        writer.writeAttribute(HtmlAttributes.TITLE, title, true);
      }
      int maxLength = 0;
      for (Validator validator : input.getValidators()) {
        if (validator instanceof LengthValidator) {
          LengthValidator lengthValidator = (LengthValidator) validator;
          maxLength = lengthValidator.getMaximum();
        }
      }
      if (maxLength > 0) {
        writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
      }
View Full Code Here

        writer.writeAttribute(HtmlAttributes.TITLE, title, true);
      }
      int maxLength = 0;
      for (Validator validator : input.getValidators()) {
        if (validator instanceof LengthValidator) {
          LengthValidator lengthValidator = (LengthValidator) validator;
          maxLength = lengthValidator.getMaximum();
        }
      }
      if (maxLength > 0) {
        writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
      }
View Full Code Here

    public boolean configureTrinidadComponent(FacesContext facesContext, UIComponent uiComponent,
                                              Map<String, Object> metaData)
    {
        boolean informationAdded = false;
        //TODO
        LengthValidator lengthValidator = (LengthValidator)facesContext.getApplication()
                                            .createValidator("org.apache.myfaces.trinidad.Length");

        if(metaData.containsKey(CommonMetaDataKeys.MIN_LENGTH))
        {
            Object min = metaData.get(CommonMetaDataKeys.MIN_LENGTH);

            if(min instanceof Integer)
            {
                lengthValidator.setMinimum((Integer)min);
                informationAdded = true;
            }
        }

        if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH))
        {
            Object maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH);

            if(maxLength instanceof Integer)
            {
                if(processComponent(uiComponent))
                {
                    ReflectionUtils.tryToInvokeMethod(
                            uiComponent,
                            ReflectionUtils.tryToGetMethod(
                                    uiComponent.getClass(),
                                    "setMaximumLength",
                                    int.class),
                            maxLength);
                }
                lengthValidator.setMaximum((Integer)maxLength);
                informationAdded = true;
            }
        }

        //reInitValidators((EditableValueHolder)uiComponent, metaData); //search wrappers and call .deactivate

        if(informationAdded && lengthValidator instanceof ClientValidator)
        {
            if(uiComponent instanceof EditableValueHolder)
            {
                ((EditableValueHolder)uiComponent).addValidator(
                        new ExtValTrinidadClientValidatorWrapper((ClientValidator)lengthValidator));
            }
            else if (uiComponent instanceof CoreOutputLabel)
            {
                if(lengthValidator.getMinimum() > 0)
                {
                    ((CoreOutputLabel)uiComponent).setShowRequired(true);
                }

                if(Boolean.TRUE.equals(metaData.get(CommonMetaDataKeys.SKIP_VALIDATION)))
View Full Code Here

TOP

Related Classes of javax.faces.validator.LengthValidator

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.