|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.validation.validator.AbstractValidator
public abstract class AbstractValidator
Convenience base class for IValidator
s. This class is thread-safe and therefore it is
safe to share validators across sessions/threads.
Error messages can be registered by calling one of the error (IValidatable
)
overloads. By default this class will skip validation if the IValidatable.getValue()
returns null
. Validators that wish to validate the null
value need
to override validateOnNullValue()
and return true
.
Constructor Summary | |
---|---|
AbstractValidator()
|
Method Summary | |
---|---|
void |
error(IValidatable validatable)
Reports an error against an IValidatable instance using the Map
returned by variablesMap(IValidatable) for variable interpolations and the message
resource key returned by resourceKey() . |
void |
error(IValidatable validatable,
java.util.Map vars)
Reports an error against an IValidatable instance using the given
Map for variable interpolations and message resource key provided by
resourceKey() . |
void |
error(IValidatable validatable,
java.lang.String resourceKey)
Reports an error against an IValidatable instance using the Map
returned by variablesMap(IValidatable) for variable interpolations and the given
message resource key. |
void |
error(IValidatable validatable,
java.lang.String resourceKey,
java.util.Map vars)
Reports an error against an IValidatable instance using the given message
resource key and Map for variable interpolations. |
protected java.util.Map |
messageModel(FormComponent formComponent)
Deprecated. use variablesMap(IValidatable) instead |
protected abstract void |
onValidate(IValidatable validatable)
Validates the IValidatable instance. |
protected java.lang.String |
resourceKey()
Gets the message resource key for this validator's error message from the ApplicationSettings class. |
protected java.lang.String |
resourceKey(FormComponent formComponent)
Deprecated. use resourceKey() instead |
void |
validate(FormComponent component)
Deprecated. use variablesMap(IValidatable) instead |
void |
validate(IValidatable validatable)
Validates the IValidatable instance. |
boolean |
validateOnNullValue()
Indicates whether or not to validate the value if it is null . |
protected java.util.Map |
variablesMap(IValidatable validatable)
Gets the default Map of variables. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractValidator()
Method Detail |
---|
public boolean validateOnNullValue()
null
. It is usually
desirable to skip validation if the value is null
, unless we want to make
sure the value is in fact null
(a rare use case). Validators that extend this
and wish to ensure the value is null
should override this method and return
true
.
true
to validate on null
value, false
to
skip validation on null
valueprotected abstract void onValidate(IValidatable validatable)
IValidatable
instance.
validatable
- the given IValidatable
instancepublic final void validate(IValidatable validatable)
IValidator
IValidatable
instance. Validation errors should be reported
using the IValidatable.error(IValidationError)
method.
validate
in interface IValidator
validatable
- the IValidatable
instance being validatedIValidator.validate(IValidatable)
public void error(IValidatable validatable)
IValidatable
instance using the Map
returned by variablesMap(IValidatable)
for variable interpolations and the message
resource key returned by resourceKey()
.
validatable
- the IValidatable
instance being validatedpublic void error(IValidatable validatable, java.lang.String resourceKey)
IValidatable
instance using the Map
returned by variablesMap(IValidatable)
for variable interpolations and the given
message resource key.
validatable
- the IValidatable
instance being validatedresourceKey
- the message resource key to usepublic void error(IValidatable validatable, java.util.Map vars)
IValidatable
instance using the given
Map
for variable interpolations and message resource key provided by
resourceKey()
.
validatable
- the IValidatable
instance being validatedvars
- Map
of variables for variable interpolationpublic void error(IValidatable validatable, java.lang.String resourceKey, java.util.Map vars)
IValidatable
instance using the given message
resource key and Map
for variable interpolations.
validatable
- the IValidatable
instance being validatedresourceKey
- the message resource key to usevars
- Map
of variables for variable interpolationprotected java.lang.String resourceKey()
ApplicationSettings
class.
NOTE: THIS METHOD SHOULD NEVER RETURN null
.
protected java.util.Map variablesMap(IValidatable validatable)
Map
of variables.
NOTE: THIS METHOD SHOULD NEVER RETURN null
.
validatable
- the IValidatable
instance being validated
Map
of variables for variable interpolationprotected final java.util.Map messageModel(FormComponent formComponent)
variablesMap(IValidatable)
instead
Component
- either comes from
FormComponent.labelModel
or resource key [form-id].[form-component-id] in that
order
formComponent
- form component
java.lang.UnsupportedOperationException
- FIXME 2.0: remove asapprotected final java.lang.String resourceKey(FormComponent formComponent)
resourceKey()
instead
formComponent
- form component that is being validated
java.lang.UnsupportedOperationException
- FIXME 2.0: remove asappublic final void validate(FormComponent component)
variablesMap(IValidatable)
instead
Instead of subclassing IValidator, you should use one of the existing validators, which cover a huge number of cases, or if none satisfies your need, subclass AbstractValidator.
Validates the given input. The input corresponds to the input from the request for a component.
component
- Component to validate
java.lang.UnsupportedOperationException
- FIXME 2.0: remove asap
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |