org.apache.wicket.validation
Class ValidationError

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

public class ValidationError
extends java.lang.Object
implements IValidationError, IClusterable

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 addMessageKey(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()
          Constructor.
 
Method Summary
 ValidationError addMessageKey(java.lang.String key)
          Adds a key to the list of keys that will be tried against IErrorMessageSource to locate the error message string.
 java.lang.String getErrorMessage(IErrorMessageSource messageSource)
          Retrieves the error message (usually user-facing).
 java.lang.String getMessage()
          Gets the default message that will be used when no message could be located via message keys.
 java.util.Map getVariables()
          Retrieves the variables map for this error.
 ValidationError setMessage(java.lang.String message)
          Sets message that will be used when no message could be located via message keys.
 ValidationError setVariable(java.lang.String name, java.lang.Object value)
          Sets a key and value in the variables map for use in substitution.
 ValidationError setVariables(java.util.Map vars)
          Sets the variables map for this error.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValidationError

public ValidationError()
Constructor.

Method Detail

addMessageKey

public ValidationError addMessageKey(java.lang.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

setVariable

public ValidationError setVariable(java.lang.String name,
                                   java.lang.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 java.util.Map 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(java.util.Map vars)
Sets the variables map for this error.

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

getErrorMessage

public final java.lang.String 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 String
See Also:
IValidationError.getErrorMessage(IErrorMessageSource)

getMessage

public final java.lang.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(java.lang.String message)
Sets message that will be used when no message could be located via message keys.

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

toString

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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.