public void validate()

in myfaces-html5-core/src/main/java/org/apache/myfaces/html5/validator/DateTimeRangeValidator.java [65:157]


    public void validate(FacesContext context, UIComponent uiComponent, Object value) throws ValidatorException
    {
        if (context == null)
            throw new NullPointerException("facesContext");
        if (uiComponent == null)
            throw new NullPointerException("uiComponent");

        if (value == null)
        {
            return;
        }

        if (uiComponent instanceof HtmlInputDateTime)
        {
            HtmlInputDateTime component = (HtmlInputDateTime) uiComponent;

            if (value instanceof Date)
            {
                Date dateValue = (Date) value;
                Date resolvedMinimum = null;
                try
                {
                    resolvedMinimum = getResolvedMinimum(component.getType());
                }
                catch (ParseException e)
                {
                    throw new ValidatorException(new FacesMessage("Unable to resolve minimum for component "
                            + DebugUtils.getPathToComponent(uiComponent) + "."), e);
                }

                Date resolvedMaximum = null;
                try
                {
                    resolvedMaximum = getResolvedMaximum(component.getType());
                }
                catch (ParseException e)
                {
                    throw new ValidatorException(new FacesMessage("Unable to resolve maximum for component "
                            + DebugUtils.getPathToComponent(uiComponent) + "."), e);
                }

                if (resolvedMinimum != null && resolvedMaximum != null)
                {
                    if (!resolvedMinimum.before(resolvedMaximum))
                    {
                        // not a ValidatorException since state is illegal
                        throw new FacesException("Minimum value is before than maximum for component "
                                + DebugUtils.getPathToComponent(uiComponent) + ".");
                    }
                    else
                    {
                        if (dateValue.before(resolvedMinimum) || dateValue.after(resolvedMaximum))
                        {
                            if (this.notInRangeMessage != null && this.notInRangeMessage.length() > 0)
                                throw new ValidatorException(new FacesMessage(this.notInRangeMessage));
                            else
                                throw new ValidatorException(
                                        new FacesMessage("Submitted value is not in allowed range for component "
                                                + DebugUtils.getPathToComponent(uiComponent) + ". Range is "
                                                + resolvedMinimum.toString() + " - " + resolvedMaximum.toString() + "."));
                        }
                    }
                }

                if (resolvedMinimum != null && dateValue.before(resolvedMinimum))
                {
                    if (this.lessThanMinimumMessage != null && this.lessThanMinimumMessage.length() > 0)
                        throw new ValidatorException(new FacesMessage(this.lessThanMinimumMessage));
                    else
                        throw new ValidatorException(new FacesMessage("Value is before minimum for component "
                                + DebugUtils.getPathToComponent(uiComponent) + ". Minimum value is "
                                + resolvedMinimum.toString() + "."));
                }

                if (resolvedMaximum != null && dateValue.after(resolvedMaximum))
                {
                    if (this.exceedMaximumMessage != null && this.exceedMaximumMessage.length() > 0)
                        throw new ValidatorException(new FacesMessage(this.exceedMaximumMessage));
                    else
                        throw new ValidatorException(new FacesMessage("Value is after maximum for component "
                                + DebugUtils.getPathToComponent(uiComponent) + ". Maximum value is "
                                + resolvedMaximum.toString() + "."));
                }
            }
        }
        else
        {
            // noop
            if (log.isLoggable(Level.WARNING))
                log.warning("DateTimeRangeValidator can only be applied to instances of HtmlInputDateTime components.");

        }
    }