org.apache.struts.taglib.html

Class JavascriptValidatorTag


public class JavascriptValidatorTag
extends BodyTagSupport

Custom tag that generates JavaScript for client side validation based on the validation rules loaded by the ValidatorPlugIn defined in the struts-config.xml file.

Version:
$Revision: 1.28 $ $Date: 2003/05/22 01:29:47 $

Author:
David Winterfeldt

Since:
Struts 1.1

Field Summary

protected String
bundle
The servlet context attribute key for our resources.
protected String
cdata
Hide JavaScript methods in a CDATA section for XHTML when "true".
protected static Locale
defaultLocale
Deprecated. This variable is no longer used.
protected String
dynamicJavascript
The dynamic JavaScript objects will only be generated if this is set to "true".
protected String
formName
The name of the form that corresponds with the action name in struts-config.xml.
private String
htmlBeginComment
protected String
htmlComment
The JavaScript methods will enclosed with html comments if this is set to "true".
private String
htmlEndComment
protected static String
lineEnd
The line ending string.
protected String
methodName
This will be used as is for the JavaScript validation method name if it has a value.
protected int
page
The current page number of a multi-part form.
protected String
src
The src attribute for html script element (used to include an external script resource).
protected String
staticJavascript
The static JavaScript methods will only be printed if this is set to "true".

Method Summary

int
doStartTag()
Render the JavaScript for to perform validations based on the form name.
String
getCdata()
Returns the cdata setting "true" or "false".
String
getDynamicJavascript()
Gets whether or not to generate the dynamic JavaScript.
String
getFormName()
Gets the key (form name) that will be used to retrieve a set of validation rules to be performed on the bean passed in for validation.
String
getHtmlComment()
Gets whether or not to delimit the JavaScript with html comments.
protected String
getJavascriptBegin(String methods)
Returns the opening script element and some initial javascript.
protected String
getJavascriptEnd()
Returns the closing script element.
protected String
getJavascriptStaticMethods(ValidatorResources resources)
String
getMethod()
Gets the method name that will be used for the Javascript validation method name if it has a value.
private String
getNextVar(String input)
The value null will be returned at the end of the sequence.
int
getPage()
Gets the current page number of a multi-part form.
String
getSrc()
Gets the src attribute's value when defining the html script element.
private String
getStartElement()
Constructs the beginning <script> element depending on xhtml status.
String
getStaticJavascript()
Gets whether or not to generate the static JavaScript.
private boolean
isXhtml()
Returns true if this is an xhtml page.
void
release()
Release any acquired resources.
private String
replaceChar(String input, int pos, char c)
Replaces a single character in a String
void
setCdata(String cdata)
Sets the cdata status.
void
setDynamicJavascript(String dynamicJavascript)
Sets whether or not to generate the dynamic JavaScript.
void
setFormName(String formName)
Sets the key (form name) that will be used to retrieve a set of validation rules to be performed on the bean passed in for validation.
void
setHtmlComment(String htmlComment)
Sets whether or not to delimit the JavaScript with html comments.
void
setMethod(String methodName)
Sets the method name that will be used for the Javascript validation method name if it has a value.
void
setPage(int page)
Sets the current page number of a multi-part form.
void
setSrc(String src)
Sets the src attribute's value when defining the html script element.
void
setStaticJavascript(String staticJavascript)
Sets whether or not to generate the static JavaScript.

Field Details

bundle

protected String bundle
The servlet context attribute key for our resources.


cdata

protected String cdata
Hide JavaScript methods in a CDATA section for XHTML when "true".


defaultLocale

protected static Locale defaultLocale

Deprecated. This variable is no longer used.

The default locale on our server.


dynamicJavascript

protected String dynamicJavascript
The dynamic JavaScript objects will only be generated if this is set to "true".


formName

protected String formName
The name of the form that corresponds with the action name in struts-config.xml. Specifying a form name places a <script> </script> around the javascript.


htmlBeginComment

private String htmlBeginComment


htmlComment

protected String htmlComment
The JavaScript methods will enclosed with html comments if this is set to "true".


htmlEndComment

private String htmlEndComment


lineEnd

protected static String lineEnd
The line ending string.


methodName

protected String methodName
This will be used as is for the JavaScript validation method name if it has a value. This is the method name of the main JavaScript method that the form calls to perform validations.


page

protected int page
The current page number of a multi-part form. Only valid when the formName attribute is set.


src

protected String src
The src attribute for html script element (used to include an external script resource). The src attribute is only recognized when the formName attribute is specified.


staticJavascript

protected String staticJavascript
The static JavaScript methods will only be printed if this is set to "true".

Method Details

doStartTag

public int doStartTag()
            throws JspException
Render the JavaScript for to perform validations based on the form name.


getCdata

public String getCdata()
Returns the cdata setting "true" or "false".

Returns:
String - "true" if JavaScript will be hidden in a CDATA section


getDynamicJavascript

public String getDynamicJavascript()
Gets whether or not to generate the dynamic JavaScript. If this is set to 'true', which is the default, the dynamic JavaScript will be generated.


getFormName

public String getFormName()
Gets the key (form name) that will be used to retrieve a set of validation rules to be performed on the bean passed in for validation.


getHtmlComment

public String getHtmlComment()
Gets whether or not to delimit the JavaScript with html comments. If this is set to 'true', which is the default, the htmlComment will be surround the JavaScript.


getJavascriptBegin

protected String getJavascriptBegin(String methods)
Returns the opening script element and some initial javascript.


getJavascriptEnd

protected String getJavascriptEnd()
Returns the closing script element.


getJavascriptStaticMethods

protected String getJavascriptStaticMethods(ValidatorResources resources)


getMethod

public String getMethod()
Gets the method name that will be used for the Javascript validation method name if it has a value. This overrides the auto-generated method name based on the key (form name) passed in.


getNextVar

private String getNextVar(String input)
The value null will be returned at the end of the sequence.     ex: "zz" will return null


getPage

public int getPage()
Gets the current page number of a multi-part form. Only field validations with a matching page numer will be generated that match the current page number. Only valid when the formName attribute is set.


getSrc

public String getSrc()
Gets the src attribute's value when defining the html script element.


getStartElement

private String getStartElement()
Constructs the beginning <script> element depending on xhtml status.


getStaticJavascript

public String getStaticJavascript()
Gets whether or not to generate the static JavaScript. If this is set to 'true', which is the default, the static JavaScript will be generated.


isXhtml

private boolean isXhtml()
Returns true if this is an xhtml page.


release

public void release()
Release any acquired resources.


replaceChar

private String replaceChar(String input,
                           int pos,
                           char c)
Replaces a single character in a String


setCdata

public void setCdata(String cdata)
Sets the cdata status.

Parameters:
cdata - The cdata to set


setDynamicJavascript

public void setDynamicJavascript(String dynamicJavascript)
Sets whether or not to generate the dynamic JavaScript. If this is set to 'true', which is the default, the dynamic JavaScript will be generated.


setFormName

public void setFormName(String formName)
Sets the key (form name) that will be used to retrieve a set of validation rules to be performed on the bean passed in for validation. Specifying a form name places a <script> </script> tag around the javascript.


setHtmlComment

public void setHtmlComment(String htmlComment)
Sets whether or not to delimit the JavaScript with html comments. If this is set to 'true', which is the default, the htmlComment will be surround the JavaScript.


setMethod

public void setMethod(String methodName)
Sets the method name that will be used for the Javascript validation method name if it has a value. This overrides the auto-generated method name based on the key (form name) passed in.


setPage

public void setPage(int page)
Sets the current page number of a multi-part form. Only field validations with a matching page numer will be generated that match the current page number. Only valid when the formName attribute is set.


setSrc

public void setSrc(String src)
Sets the src attribute's value when defining the html script element. The src attribute is only recognized when the formName attribute is specified.


setStaticJavascript

public void setStaticJavascript(String staticJavascript)
Sets whether or not to generate the static JavaScript. If this is set to 'true', which is the default, the static JavaScript will be generated.


Copyright B) 2000-2005 - Apache Software Foundation