Class StringValidator

  • All Implemented Interfaces:
    java.io.Serializable, IComponentAwareEventSink, IComponentAwareHeaderContributor, org.apache.wicket.util.io.IClusterable, IValidator<java.lang.String>

    public class StringValidator
    extends AbstractRangeValidator<java.lang.Integer,​java.lang.String>
    Validator for checking if length of a string falls within [min,max] range. If either min or max are null they are not checked.

    If the component is attached to an input tag, a maxlen attribute will be added if the maximum is set. *

    Resource keys:

    Error Message Variables:

    • name: the id of Component that failed
    • label: the label of the Component (either comes from FormComponent.labelModel or resource key <form-id>.<form-component-id>
    • input: the input value
    • length: the length of the entered
    • minimum: the minimum allowed length
    • maximum: the maximum allowed length

    Author:
    igor
    See Also:
    Serialized Form
    • Constructor Detail

      • StringValidator

        public StringValidator​(java.lang.Integer minimum,
                               java.lang.Integer maximum)
        Constructor that sets the minimum and maximum length values.
        Parameters:
        minimum - the minimum length
        maximum - the maximum length
    • Method Detail

      • getValue

        protected java.lang.Integer getValue​(IValidatable<java.lang.String> validatable)
        Description copied from class: AbstractRangeValidator
        Gets the value that should be validated against the range
        Specified by:
        getValue in class AbstractRangeValidator<java.lang.Integer,​java.lang.String>
        Returns:
        value to validate
      • onComponentTag

        public void onComponentTag​(Component component,
                                   ComponentTag tag)
        Description copied from class: Behavior
        Called any time a component that has this behavior registered is rendering the component tag.
        Overrides:
        onComponentTag in class Behavior
        Parameters:
        component - the component that renders this tag currently
        tag - the tag that is rendered
      • hasLengthAttribute

        protected boolean hasLengthAttribute​(java.lang.String tagName)
      • exactLength

        public static StringValidator exactLength​(int length)
        Parameters:
        length -
        Returns:
        a StringValidator that generates an error if a string is not of an exact length
      • maximumLength

        public static StringValidator maximumLength​(int length)
        Parameters:
        length -
        Returns:
        a StringValidator that generates an error if a string exceeds a maximum length
      • minimumLength

        public static StringValidator minimumLength​(int length)
        Parameters:
        length -
        Returns:
        a StringValidator that generates an error if a string is not of a minimum length
      • lengthBetween

        public static StringValidator lengthBetween​(int minimum,
                                                    int maximum)
        Parameters:
        minimum -
        maximum -
        Returns:
        a StringValidator that generates an error if the length of a string is not between (inclusive) minimum and maximum