org.apache.velocity.tools.struts
Class ErrorsTool

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

public class ErrorsTool
extends MessageResourcesTool

View tool to work with the Struts error messages.

 Template example(s):
   #if( $errors.exist() )
     <div class="errors">
     #foreach( $e in $errors.all )
       $e <br>
     #end
     </div>
   #end

 Toolbox configuration:
 <tool>
   <key>errors</key>
   <scope>request</scope>
   <class>org.apache.velocity.tools.struts.ErrorsTool</class>
 </tool>
 

This tool should only be used in the request scope.

Since:
VelocityTools 1.0
Version:
$Id: ErrorsTool.java,v 1.9 2003/11/06 18:03:43 nbubna Exp $
Author:
Gabe Sidler

Field Summary
protected  org.apache.struts.action.ActionErrors errors
          A reference to the queued action messages.
 
Fields inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
application, locale, request, resources
 
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 get(java.lang.String property, java.lang.String bundle)
          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.
 java.lang.String getMsgs(java.lang.String property, java.lang.String bundle)
          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 org.apache.velocity.tools.struts.MessageResourcesTool
getResources
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Overrides:
init in class MessageResourcesTool
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

get

public java.util.ArrayList get(java.lang.String property,
                               java.lang.String bundle)
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
bundle - the message resource bundle to use
Since:
VelocityTools 1.1

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.

getMsgs

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

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
bundle - the message resource bundle to use
Returns:
The formatted error messages. If no error messages are queued, an empty string is returned.
Since:
VelocityTools 1.1

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