org.apache.wicket.validation.validator
Class StringValidator

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.apache.wicket.validation.validator.AbstractRangeValidator<Integer,String>
          extended by org.apache.wicket.validation.validator.StringValidator
All Implemented Interfaces:
Serializable, IComponentAwareEventSink, IComponentAwareHeaderContributor, IClusterable, IValidator<String>

public class StringValidator
extends AbstractRangeValidator<Integer,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:

Author:
igor
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.validation.validator.AbstractRangeValidator
AbstractRangeValidator.Mode
 
Constructor Summary
protected StringValidator()
          Constructor used for subclasses who want to set the range using AbstractRangeValidator.setRange(Comparable, Comparable)
  StringValidator(Integer minimum, Integer maximum)
          Constructor that sets the minimum and maximum length values.
 
Method Summary
protected  ValidationError decorate(ValidationError error, IValidatable<String> validatable)
          Allows subclasses to decorate reported errors
static StringValidator exactLength(int length)
           
protected  Integer getValue(IValidatable<String> validatable)
          Gets the value that should be validated against the range
static StringValidator lengthBetween(int minimum, int maximum)
           
static StringValidator maximumLength(int length)
           
static StringValidator minimumLength(int length)
           
 void onComponentTag(Component component, ComponentTag tag)
          Called any time a component that has this behavior registered is rendering the component tag.
 
Methods inherited from class org.apache.wicket.validation.validator.AbstractRangeValidator
getMaximum, getMinimum, getMode, setRange, validate
 
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, bind, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onConfigure, onEvent, onException, onRemove, renderHead, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringValidator

public StringValidator(Integer minimum,
                       Integer maximum)
Constructor that sets the minimum and maximum length values.

Parameters:
minimum - the minimum lenghh
maximum - the maximum length

StringValidator

protected StringValidator()
Constructor used for subclasses who want to set the range using AbstractRangeValidator.setRange(Comparable, Comparable)

Method Detail

getValue

protected Integer getValue(IValidatable<String> validatable)
Description copied from class: AbstractRangeValidator
Gets the value that should be validated against the range

Specified by:
getValue in class AbstractRangeValidator<Integer,String>
Returns:
value to validate

decorate

protected ValidationError decorate(ValidationError error,
                                   IValidatable<String> validatable)
Description copied from class: AbstractRangeValidator
Allows subclasses to decorate reported errors

Overrides:
decorate in class AbstractRangeValidator<Integer,String>
Returns:
decorated error

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

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


Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.