org.apache.struts.taglib.html
Class JavascriptValidatorTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.apache.struts.taglib.html.JavascriptValidatorTag
All Implemented Interfaces:
Serializable, BodyTag, IterationTag, Tag
Direct Known Subclasses:
ELJavascriptValidatorTag

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.

Since:
Struts 1.1
Version:
$Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
See Also:
Serialized Form

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  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.
protected static String HTML_BEGIN_COMMENT
          The start of the HTML comment hiding JavaScript from old browsers.
protected static String HTML_END_COMMENT
          The end of the HTML comment hiding JavaScript from old browsers.
protected  String htmlComment
          The JavaScript methods will enclosed with html comments if this is set to "true".
protected  String jsFormName
          formName is used for both Javascript and non-javascript validations.
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  boolean scriptLanguage
          Include language attribute in the <script> element.
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".
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
JavascriptValidatorTag()
           
 
Method Summary
 int doStartTag()
          Render the JavaScript for to perform validations based on the form name.
 String getBundle()
          Sets the servlet context attribute key for our resources.
 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 getJsFormName()
           
 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.
 boolean getScriptLanguage()
          Gets whether or not the <script> element will include the language attribute.
 String getSrc()
          Gets the src attribute's value when defining the html script element.
 String getStaticJavascript()
          Gets whether or not to generate the static JavaScript.
 void release()
          Release any acquired resources.
protected  String renderJavascript()
          Returns fully rendered JavaScript.
protected  String renderStartElement()
          Constructs the beginning <script> element depending on XHTML status.
 void setBundle(String bundle)
          Gets the servlet context attribute key for our resources.
 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 setJsFormName(String jsFormName)
           
 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 setScriptLanguage(boolean scriptLanguage)
          Sets whether or not the <script> element will include the language attribute.
 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.
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doEndTag, doInitBody, getBodyContent, getPreviousOut, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Field Detail

HTML_BEGIN_COMMENT

protected static final String HTML_BEGIN_COMMENT
The start of the HTML comment hiding JavaScript from old browsers.

Since:
Struts 1.2
See Also:
Constant Field Values

HTML_END_COMMENT

protected static final String HTML_END_COMMENT
The end of the HTML comment hiding JavaScript from old browsers.

Since:
Struts 1.2
See Also:
Constant Field Values

lineEnd

protected static String lineEnd
The line ending string.


bundle

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


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.


jsFormName

protected String jsFormName
formName is used for both Javascript and non-javascript validations. For the javascript validations, there is the possibility that we will be rewriting the formName (if it is a ValidatorActionForm instead of just a ValidatorForm) so we need another variable to hold the formName just for javascript usage.


page

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


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.


scriptLanguage

protected boolean scriptLanguage
Include language attribute in the <script> element. This property is ignored in XHTML mode.

Since:
Struts 1.2

staticJavascript

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


dynamicJavascript

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


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.


htmlComment

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


cdata

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

Constructor Detail

JavascriptValidatorTag

public JavascriptValidatorTag()
Method Detail

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.


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.


getJsFormName

public String getJsFormName()
Returns:
Returns the jsFormName.

setJsFormName

public void setJsFormName(String jsFormName)
Parameters:
jsFormName - The jsFormName to set.

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.


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.


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.


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.


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.


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.


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.


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.


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.


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.


getSrc

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


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.


getBundle

public String getBundle()
Sets the servlet context attribute key for our resources.


setBundle

public void setBundle(String bundle)
Gets the servlet context attribute key for our resources.


doStartTag

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

Specified by:
doStartTag in interface Tag
Overrides:
doStartTag in class BodyTagSupport
Throws:
JspException - if a JSP exception has occurred

renderJavascript

protected String renderJavascript()
                           throws JspException
Returns fully rendered JavaScript.

Throws:
JspException
Since:
Struts 1.2

release

public void release()
Release any acquired resources.

Specified by:
release in interface Tag
Overrides:
release in class BodyTagSupport

getJavascriptBegin

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


getJavascriptStaticMethods

protected String getJavascriptStaticMethods(ValidatorResources resources)

getJavascriptEnd

protected String getJavascriptEnd()
Returns the closing script element.


renderStartElement

protected String renderStartElement()
Constructs the beginning <script> element depending on XHTML status.

Since:
Struts 1.2

getCdata

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

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

setCdata

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

Parameters:
cdata - The cdata to set

getScriptLanguage

public boolean getScriptLanguage()
Gets whether or not the <script> element will include the language attribute.

Returns:
true if language attribute will be included.
Since:
Struts 1.2

setScriptLanguage

public void setScriptLanguage(boolean scriptLanguage)
Sets whether or not the <script> element will include the language attribute.

Since:
Struts 1.2


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.