Package javax.faces.validator

Examples of javax.faces.validator.DoubleRangeValidator


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


    @Override
    protected String getMessageId(Validator component) {
        // TODO: all messages should be passed to client side using js function RichFaces.csv.addMessage
        String messageId;
        if (component instanceof DoubleRangeValidator) {
            DoubleRangeValidator validator = (DoubleRangeValidator) component;
            if (validator.getMaximum() < Double.MAX_VALUE) {
                if (validator.getMinimum() > Double.MIN_VALUE) {
                    messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
                } else {
                    messageId = DoubleRangeValidator.MAXIMUM_MESSAGE_ID;
                }
            } else if (validator.getMinimum() > Double.MIN_VALUE) {
                messageId = DoubleRangeValidator.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 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

    }

    @Override
    protected void fillParameters(BaseFacesObjectDescriptor<Validator> descriptor, Validator component) {
        if (component instanceof DoubleRangeValidator) {
            DoubleRangeValidator validator = (DoubleRangeValidator) component;
            if (validator.getMaximum() < Double.MAX_VALUE) {
                descriptor.addParameter(MAXIMUM, validator.getMaximum());
            }
            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

            UIComponent uiComponent, MetaDataEntry metaDataEntry,
            Object convertedObject) throws ValidatorException
    {

        DoubleRange annotation = metaDataEntry.getValue(DoubleRange.class);
        DoubleRangeValidator doubleRangeValidator = (DoubleRangeValidator)facesContext.getApplication()
                                                        .createValidator("javax.faces.DoubleRange");

        if(annotation.minimum() != Double.MIN_VALUE)
        {
            doubleRangeValidator.setMinimum(annotation.minimum());
        }

        if(annotation.maximum() != Double.MAX_VALUE)
        {
            doubleRangeValidator.setMaximum(annotation.maximum());
        }

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

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

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

    @Override
    protected Validator createValidator() throws JspException
    {
        setValidatorIdString(VALIDATOR_ID);
        DoubleRangeValidator validator = (DoubleRangeValidator)super.createValidator();
        if (null != _min)
        {
            validator.setMinimum(_min);
        }
        if (null != _max)
        {
            validator.setMaximum(_max);
        }
        return validator;
    }
View Full Code Here

                subValidators.add(new LongRangeValidator(Long.MAX_VALUE, Long.MIN_VALUE));
                break;
            }

            case FLOAT: {
                subValidators.add(new DoubleRangeValidator(Float.MAX_VALUE, Float.MIN_VALUE));
                break;
            }

            case DOUBLE: {
                subValidators.add(new DoubleRangeValidator(Double.MAX_VALUE, Double.MIN_VALUE));
                break;
                // There is no need for type-based validators for booleans or enums, because the UI input controls
                // (e.g. radio buttons or pulldown menus) prevent invalid values from being entered.
            }
            }
View Full Code Here

            }

            validator = longRangeValidator;
        } else if (constraint instanceof FloatRangeConstraint) {
            FloatRangeConstraint floatRangeConstraint = (FloatRangeConstraint) constraint;
            DoubleRangeValidator doubleRangeValidator = new DoubleRangeValidator();
            Double minValue = floatRangeConstraint.getMinimum();
            if (minValue != null) {
                doubleRangeValidator.setMinimum(minValue);
            }

            Double maxValue = floatRangeConstraint.getMaximum();
            if (maxValue != null) {
                doubleRangeValidator.setMaximum(maxValue);
            }

            validator = doubleRangeValidator;
        } else if (constraint instanceof RegexConstraint) {
            RegexConstraint regexConstraint = (RegexConstraint) constraint;
View Full Code Here

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

TOP

Related Classes of javax.faces.validator.DoubleRangeValidator

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.