net.sourceforge.stripes.validation
Class ScopedLocalizableError

java.lang.Object
  extended by net.sourceforge.stripes.action.SimpleMessage
      extended by net.sourceforge.stripes.validation.SimpleError
          extended by net.sourceforge.stripes.validation.LocalizableError
              extended by net.sourceforge.stripes.validation.ScopedLocalizableError
All Implemented Interfaces:
Serializable, Message, ValidationError

public class ScopedLocalizableError
extends LocalizableError

Provides a slightly more customizable approach to error messages. Where the LocalizedError class looks for an error message in a single place based on the key provided, ScopedLocalizableError performs a scoped search for an error message.

As an example, let's say that the IntegerConverter raises an error message with the values defaultScope=converter.integer and key=outOfRange, for a field called age on an ActionBean bound to /cats/KittenDetail.action. Based on this information an instance of ScopedLocalizableError would fetch the resource bundle and look for error message templates in the following order:

Using ScopingLocalizedErrors provides application developers with the flexibility to provide as much or as little specificity in error messages as desired. The scope and ordering of the messages is designed to allow developers to specify default messages at several levels, and then override those as needed for specific circumstances.

Author:
Tim Fennell
See Also:
Serialized Form

Field Summary
static String DEFAULT_NAME
          Default key that is used for looking up error messages.
 
Constructor Summary
ScopedLocalizableError(String defaultScope, String key, Object... parameters)
          Constructs a ScopedLocalizableError with the supplied information.
 
Method Summary
 boolean equals(Object o)
          Generated equals method that checks all fields and super.equals().
 String getDefaultScope()
          Get the default scope that was passed into the constructor.
 String getKey()
          Get the key that was passed into the constructor.
protected  String getMessageTemplate(Locale locale)
          Overrides getMessageTemplate to perform a scoped search for a message template as defined in the class level javadoc.
 int hashCode()
          Generated hashCode() method.
 
Methods inherited from class net.sourceforge.stripes.validation.LocalizableError
getMessageKey
 
Methods inherited from class net.sourceforge.stripes.validation.SimpleError
getActionPath, getBeanclass, getFieldName, getFieldValue, getMessage, resolveFieldName, setActionPath, setBeanclass, setFieldName, setFieldValue
 
Methods inherited from class net.sourceforge.stripes.action.SimpleMessage
getMessage, getReplacementParameters
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAME

public static final String DEFAULT_NAME
Default key that is used for looking up error messages.

See Also:
Constant Field Values
Constructor Detail

ScopedLocalizableError

public ScopedLocalizableError(String defaultScope,
                              String key,
                              Object... parameters)
Constructs a ScopedLocalizableError with the supplied information.

Parameters:
defaultScope - the default scope under which to look for the error message should more specifically scoped lookups fail
key - the name of the message to lookup
parameters - an optional number of replacement parameters to be used in the message
Method Detail

getDefaultScope

public String getDefaultScope()
Get the default scope that was passed into the constructor.

See Also:
ScopedLocalizableError(String, String, Object...)

getKey

public String getKey()
Get the key that was passed into the constructor.

See Also:
ScopedLocalizableError(String, String, Object...)

getMessageTemplate

protected String getMessageTemplate(Locale locale)
Overrides getMessageTemplate to perform a scoped search for a message template as defined in the class level javadoc.

Overrides:
getMessageTemplate in class LocalizableError
Parameters:
locale - the Locale of the message template desired
Returns:
the message (potentially with TextFormat replacement tokens).

equals

public boolean equals(Object o)
Generated equals method that checks all fields and super.equals().

Overrides:
equals in class LocalizableError
Parameters:
o - another object that is a SimpleMessage or subclass thereof
Returns:
true if the two objects will generate the same user message, false otherwise

hashCode

public int hashCode()
Generated hashCode() method.

Overrides:
hashCode in class LocalizableError


? Copyright 2005-2006, Stripes Development Team.