org.apache.wicket.validation
Class ValidationError

java.lang.Object
  extended by org.apache.wicket.validation.ValidationError
All Implemented Interfaces:
Serializable, IClusterable, IValidationError

public final class ValidationError
extends Object
implements IValidationError

A versatile implementation of IValidationError that supports message resolution from IErrorMessageSource, default message (if none of the keys matched), and variable substitution. The final error message is constructed via the following process:

  1. Try all keys added by calls to addKey(String) via the provided IErrorMessageSource.
  2. If none of the keys yielded a message, use the message set by setMessage(String), if any.
  3. Perform variable substitution on the message, if any.

Since:
1.2.6
Author:
Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Constructor Summary
ValidationError()
          Constructs an empty error
ValidationError(IValidator<?> validator)
          Constructs a validation error with the validator's standard key.
ValidationError(IValidator<?> validator, String variation)
          Constructs a validation error with a variation of validator's standard key.
ValidationError(String message)
          Constructs a validation error with the specified message.
 
Method Summary
 ValidationError addKey(IValidator<?> validator)
          Shortcut for adding a standard message key which is the simple name of the validator' class
 ValidationError addKey(IValidator<?> validator, String variation)
          Shortcut for adding a standard message key variation which is the simple name of the validator class followed by a dot and the variation
 ValidationError addKey(String key)
          Adds a key to the list of keys that will be tried against IErrorMessageSource to locate the error message string.
 ValidationError addMessageKey(String key)
          Deprecated. use addKey(String)
 Serializable getErrorMessage(IErrorMessageSource messageSource)
          Retrieves the error message (usually user-facing).
 List<String> getKeys()
          Gets error keys
 String getMessage()
          Gets the default message that will be used when no message could be located via message keys.
 Map<String,Object> getVariables()
          Retrieves the variables map for this error.
 void setKeys(List<String> keys)
          Sets error keys
 ValidationError setMessage(String message)
          Sets message that will be used when no message could be located via message keys.
 ValidationError setVariable(String name, Object value)
          Sets a key and value in the variables map for use in substitution.
 ValidationError setVariables(Map<String,Object> vars)
          Sets the variables map for this error.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValidationError

public ValidationError()
Constructs an empty error


ValidationError

public ValidationError(IValidator<?> validator)
Constructs a validation error with the validator's standard key. Equivalent to calling addKey(IValidator)

Parameters:
validator - validator

ValidationError

public ValidationError(IValidator<?> validator,
                       String variation)
Constructs a validation error with a variation of validator's standard key. Equivalent to calling addKey(IValidator, String)

Parameters:
validator - validator
variation - key variation

ValidationError

public ValidationError(String message)
Constructs a validation error with the specified message. Equivalent to calling setMessage(String)

Parameters:
message - message
Method Detail

addMessageKey

@Deprecated
public ValidationError addMessageKey(String key)
Deprecated. use addKey(String)

Adds a key to the list of keys that will be tried against IErrorMessageSource to locate the error message string.

Parameters:
key -
Returns:
this ValidationError for chaining purposes

addKey

public ValidationError addKey(String key)
Adds a key to the list of keys that will be tried against IErrorMessageSource to locate the error message string.

Parameters:
key - a message key to be added
Returns:
this ValidationError for chaining purposes

addKey

public ValidationError addKey(IValidator<?> validator)
Shortcut for adding a standard message key which is the simple name of the validator' class

Parameters:
validator - validator
Returns:
this

addKey

public ValidationError addKey(IValidator<?> validator,
                              String variation)
Shortcut for adding a standard message key variation which is the simple name of the validator class followed by a dot and the variation

If the variation is empty only the validator's simple class name is used

Parameters:
validator - validator
variation - key variation
Returns:
this

setVariable

public ValidationError setVariable(String name,
                                   Object value)
Sets a key and value in the variables map for use in substitution.

Parameters:
name - a variable name
value - a variable value
Returns:
this ValidationError for chaining purposes

getVariables

public final Map<String,Object> getVariables()
Retrieves the variables map for this error. The caller is free to modify the contents.

Returns:
a Map of variables for this error

setVariables

public final ValidationError setVariables(Map<String,Object> vars)
Sets the variables map for this error.

Parameters:
vars - a variables map
Returns:
this ValidationError for chaining purposes

getErrorMessage

public final Serializable getErrorMessage(IErrorMessageSource messageSource)
Description copied from interface: IValidationError
Retrieves the error message (usually user-facing).

Specified by:
getErrorMessage in interface IValidationError
Parameters:
messageSource - the message source
Returns:
the error message
See Also:
IValidationError.getErrorMessage(IErrorMessageSource)

getMessage

public final String getMessage()
Gets the default message that will be used when no message could be located via message keys.

Returns:
message the default message used when all keys yield no message

setMessage

public final ValidationError setMessage(String message)
Sets message that will be used when no message could be located via message keys.

Note: No variable substitution is performed on the given message!

Parameters:
message - a default message to be used when all keys yield no message
Returns:
this ValidationError for chaining purposes

getKeys

public List<String> getKeys()
Gets error keys

Returns:
keys

setKeys

public void setKeys(List<String> keys)
Sets error keys

Parameters:
keys -

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


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