org.apache.velocity.tools.struts
Class ValidatorTool

java.lang.Object
  extended by org.apache.velocity.tools.struts.ValidatorTool

@DefaultKey(value="validator")
@ValidScope(value="request")
public class ValidatorTool
extends java.lang.Object

View tool that works with Struts Validator to produce client side javascript validation for your forms.

Usage:

 Template example:

 $validator.getJavascript("nameOfYourForm")

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

This is an adaptation of the JavascriptValidatorTag from the Struts 1.1 validator library.

Since:
VelocityTools 1.1
Version:
$Revision: 595822 $ $Date: 2007-11-16 13:07:51 -0800 (Fri, 16 Nov 2007) $
Author:
David Winterfeldt, David Graham, Marino A. Jonsson, Nathan Bubna

Field Summary
private static java.util.Comparator actionComparator
          A Comparator to use when sorting ValidatorAction objects.
protected  javax.servlet.ServletContext app
          A reference to the ServletContext
private  boolean cdata
           
protected  ViewContext context
          A reference to the ViewContext
private  java.lang.String formName
           
private static java.lang.String HTML_BEGIN_COMMENT
           
private static java.lang.String HTML_END_COMMENT
           
private  boolean htmlComment
           
protected  java.lang.String jsFormName
          formName is used for both Javascript and non-javascript validations.
private  java.lang.String methodName
           
private  int page
           
protected  javax.servlet.http.HttpServletRequest request
          A reference to the HttpServletRequest.
protected  org.apache.commons.validator.ValidatorResources resources
          A reference to the ValidatorResources.
protected  javax.servlet.http.HttpSession session
          A reference to the HttpSession.
private  java.lang.String src
           
private  boolean xhtml
           
 
Constructor Summary
ValidatorTool()
           
 
Method Summary
 void configure(java.util.Map params)
          Initializes this tool.
protected  java.util.List createActionList(org.apache.commons.validator.ValidatorResources resources, org.apache.commons.validator.Form form)
          Get List of actions for the given Form.
protected  java.lang.String createMethods(java.util.List actions)
          Creates the JavaScript methods list from the given actions.
protected  java.lang.String escapeJavascript(java.lang.String str)
          Backslash-escapes the following characters from the input string: ", ', \, \r, \n.
 boolean getCdata()
          Returns the cdata setting "true" or "false".
 java.lang.String getDynamicJavascript()
          Render just the dynamic JavaScript to perform validations based on the form name attribute of the action mapping associated with the current request (if such exists).
 java.lang.String getDynamicJavascript(java.lang.String formName)
          Render just the dynamic JavaScript to perform validations based on the supplied form name.
protected  java.lang.String getDynamicJavascript(org.apache.commons.validator.ValidatorResources resources, java.util.Locale locale, org.apache.commons.validator.Form form)
          Generates the dynamic JavaScript for the form.
 boolean getHtmlComment()
          Gets whether or not to delimit the JavaScript with html comments.
 java.lang.String getJavascript()
          Render both dynamic and static JavaScript to perform validations based on the form name attribute of the action mapping associated with the current request (if such exists).
 java.lang.String getJavascript(java.lang.String formName)
          Render both dynamic and static JavaScript to perform validations based on the supplied form name.
protected  java.lang.String getJavascript(java.lang.String formName, boolean getStatic)
          Render both dynamic and static JavaScript to perform validations based on the supplied form name.
protected  java.lang.String getJavascriptBegin(java.lang.String methods)
          Returns the opening script element and some initial javascript.
protected  java.lang.String getJavascriptEnd()
          Returns the closing script element.
protected  java.lang.String getJavascriptStaticMethods(org.apache.commons.validator.ValidatorResources resources)
           
 java.lang.String getMethod()
          Gets the method name that will be used for the Javascript validation method name if it has a value.
 int getPage()
          Gets the current page number of a multi-part form.
 java.lang.String getSrc()
          Gets the src attribute's value when defining the html script element.
private  java.lang.String getStartElement()
          Constructs the beginning

Copyright (c) 2003-2007 Apache Software Foundation