org.apache.velocity.tools.struts
Class ErrorsTool

java.lang.Object
  |
  +--org.apache.velocity.tools.struts.ErrorsTool
All Implemented Interfaces:
ViewTool

public class ErrorsTool
extends java.lang.Object
implements ViewTool

View tool to work with the Struts error messages.

This class is equipped to be used with a toolbox manager, for example the ServletToolboxManager included with VelServlet. This class implements interface ViewTool, which allows a toolbox manager to pass the required context information.

This class is not thread-safe by design. A new instance is needed for the processing of every template request. This means this tool should only be used in the request scope, not application or session scopes.

Version:
$Id: ErrorsTool.java,v 1.4 2003/05/28 00:17:15 nbubna Exp $
Author:
Gabe Sidler

Field Summary
protected  javax.servlet.ServletContext application
          A reference to the ServletContext
protected  org.apache.struts.action.ActionErrors errors
          A reference to the queued action messages.
protected  java.util.Locale locale
          A reference to the user's locale.
protected  javax.servlet.http.HttpServletRequest request
          A reference to the HttpServletRequest.
protected  org.apache.struts.util.MessageResources resources
          A reference to the Struts message resources.
protected  javax.servlet.http.HttpSession session
          A reference to the HttpSession.
 
Constructor Summary
ErrorsTool()
          Default constructor.
 
Method Summary
 boolean exist()
          Returns true if there are action errors queued, otherwise false.
 boolean exist(java.lang.String property)
          Returns true if there are action errors queued for the specified category of errors, otherwise false.
 java.util.ArrayList get(java.lang.String property)
          Returns the set of localized error messages as an java.util.ArrayList of java.lang.String for all errors queued of the specified category or null if no error are queued for the specified category.
 java.util.ArrayList getAll()
          Returns the set of localized error messages as an java.util.ArrayList of java.lang.String for all errors queued or null if no errors are queued.
 java.util.ArrayList getGlobal()
           This a convenience method and the equivalent of $errors.get($errors.globalName).
 java.lang.String getGlobalName()
          Returns the default "GLOBAL" category name that can be used for messages that are not associated with a particular property.
 java.lang.String getMsgs()
          Renders the queued error messages as a list.
 java.lang.String getMsgs(java.lang.String property)
          Renders the queued error messages of a particual category as a list.
 int getSize()
          Returns the number of action errors queued.
 int getSize(java.lang.String property)
          Returns the number of action errors queued for a particular property.
 void init(java.lang.Object obj)
          Initializes this tool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

application

protected javax.servlet.ServletContext application
A reference to the ServletContext


request

protected javax.servlet.http.HttpServletRequest request
A reference to the HttpServletRequest.


session

protected javax.servlet.http.HttpSession session
A reference to the HttpSession.


resources

protected org.apache.struts.util.MessageResources resources
A reference to the Struts message resources.


locale

protected java.util.Locale locale
A reference to the user's locale.


errors

protected org.apache.struts.action.ActionErrors errors
A reference to the queued action messages.

Constructor Detail

ErrorsTool

public ErrorsTool()
Default constructor. Tool must be initialized before use.

Method Detail

init

public void init(java.lang.Object obj)
Initializes this tool.

Specified by:
init in interface ViewTool
Parameters:
obj - the current ViewContext
Throws:
java.lang.IllegalArgumentException - if the param is not a ViewContext

exist

public boolean exist()

Returns true if there are action errors queued, otherwise false.


exist

public boolean exist(java.lang.String property)

Returns true if there are action errors queued for the specified category of errors, otherwise false.

Parameters:
property - the category of errors to check for

getSize

public int getSize()
Returns the number of action errors queued.


getSize

public int getSize(java.lang.String property)
Returns the number of action errors queued for a particular property.

Parameters:
property - the category of errors to check for

getGlobal

public java.util.ArrayList getGlobal()

This a convenience method and the equivalent of $errors.get($errors.globalName).

Returns the set of localized error messages as an java.util.ArrayList of java.lang.String for all errors queued of the global category or null if no error are queued for the specified category.

If the message resources don't contain an error message for a particular error key, the key itself is used as error message.


getAll

public java.util.ArrayList getAll()
Returns the set of localized error messages as an java.util.ArrayList of java.lang.String for all errors queued or null if no errors are queued. If the message resources don't contain an error message for a particular error key, the key itself is used as error message.


get

public java.util.ArrayList get(java.lang.String property)
Returns the set of localized error messages as an java.util.ArrayList of java.lang.String for all errors queued of the specified category or null if no error are queued for the specified category. If the message resources don't contain an error message for a particular error key, the key itself is used as error message.

Parameters:
property - the category of errors to operate on

getMsgs

public java.lang.String getMsgs()

Renders the queued error messages as a list. This method expects the message keys errors.header and errors.footer in the message resources. The value of the former is rendered before the list of error messages and the value of the latter is rendered after the error messages.

Returns:
The formatted error messages. If no error messages are queued, an empty string is returned.

getMsgs

public java.lang.String getMsgs(java.lang.String property)

Renders the queued error messages of a particual category as a list. This method expects the message keys errors.header and errors.footer in the message resources. The value of the former is rendered before the list of error messages and the value of the latter is rendered after the error messages.

Parameters:
property - the category of errors to render
Returns:
The formatted error messages. If no error messages are queued, an empty string is returned.

getGlobalName

public java.lang.String getGlobalName()
Returns the default "GLOBAL" category name that can be used for messages that are not associated with a particular property.



Copyright (c) 2003 Apache Software Foundation