org.apache.velocity.tools.struts
Class ErrorsTool

java.lang.Object
  extended by org.apache.velocity.tools.struts.MessageResourcesTool
      extended by org.apache.velocity.tools.struts.ActionMessagesTool
          extended by org.apache.velocity.tools.struts.ErrorsTool

@DefaultKey(value="errors")
@ValidScope(value="request")
public class ErrorsTool
extends ActionMessagesTool

This tool deals with Struts error messages. Errors may stem from the validation of a submitted form or from the processing of a request. If there are errors, they are made available to the view to render. A few important aspects about errors are:

See the Struts User's Guide, section Building View Components for more information on this topic.

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

 Toolbox configuration:
 <tools>
   <toolbox scope="request">
     <tool class="org.apache.velocity.tools.struts.ErrorsTool"/>
   </toolbox>
 </tools>
 

This tool should only be used in the request scope.

Since VelocityTools 1.1, ErrorsTool extends ActionMessagesTool.

Since:
VelocityTools 1.0
Version:
$Id: ErrorsTool.java 601976 2007-12-07 03:50:51Z nbubna $
Author:
Gabe Sidler, Nathan Bubna

Field Summary
 
Fields inherited from class org.apache.velocity.tools.struts.ActionMessagesTool
actionMsgs
 
Fields inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
application, LOG, request
 
Constructor Summary
ErrorsTool()
           
 
Method Summary
protected  org.apache.struts.action.ActionMessages getActionMessages()
           
 String getMsgs()
          Renders the queued error messages as a list.
 String getMsgs(String property)
          Renders the queued error messages of a particual category as a list.
 String getMsgs(String property, String bundle)
          Renders the queued error messages of a particual category as a list.
 
Methods inherited from class org.apache.velocity.tools.struts.ActionMessagesTool
exist, exist, get, get, getAll, getAll, getGlobal, getGlobalName, getSize, getSize
 
Methods inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
configure, getLocale, getResources, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ErrorsTool

public ErrorsTool()
Method Detail

getActionMessages

protected org.apache.struts.action.ActionMessages getActionMessages()
Overrides:
getActionMessages in class ActionMessagesTool

getMsgs

public 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 String getMsgs(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 String getMsgs(String property,
                      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


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.