javawebparts.taglib.jstags
Class LocateSelectValueTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javawebparts.taglib.jstags.LocateSelectValueTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class LocateSelectValueTag
extends javax.servlet.jsp.tagext.TagSupport

This class is a custom tag that renders the JWPLocateSelectValue() Javascript function which takes in a reference to a <select> tag and locates the value in it (and selects it) that is passed in. It returns false if the value was not found at all. The third paramter in accepts determines whether the value should be selected. So if you simply want to know if a value is present, pass in false, or true to go ahead and select the value if found. The fourth parameter determines whether the search is case-sensitive or not. Pass true to do a case-insensitive search.

This tag uses the following attributes:

renderScriptTags - true/false - When set to true, the Javascript will be rendered inside a <script> </script> tag pair. When set to false, this will not be done and it is expected that the <jstags:fullTrim/> tag appears inside a <script> </script> tag pair. If this attribute is not present, the script tags WILL be rendered.

It renders the following Javascript:

function JWPLocateSelectValue(jwpsv_select, jwpsv_value, jwpsv_justFind, jwpsv_caseInsensitive) {
if (jwpsv_select == null ||
jwpsv_value == null || jwpsv_value == "" ||
jwpsv_caseInsensitive == null ||
jwpsv_justFind == null) {
return;
}
if (jwpsv_caseInsensitive) {
jwpsv_value = jwpsv_value.toLowerCase();
}
found = false;
for (i = 0; (i < jwpsv_select.length) && !found; i++) {
nextVal = jwpsv_select.options[i].value;
if (jwpsv_caseInsensitive) {
nextVal = nextVal.toLowerCase();
}
if (nextVal == jwpsv_value) {
found = true;
if (!jwpsv_justFind) {
jwpsv_select.options[i].selected = true;
}
}
}
return found;
}

Usage example:

JWPLocateSelectValue(myForm.mySelect, "opt1");
This results in the <option> element of the <select> element named "mySelect" in the <form> named "myForm" to be selected, it present. Value matching will be case-sensitive.

JWPLocateSelectValue(myForm.mySelect, "opt1", true);
This will search the above mentioned dropdown and return true of "opt1" is found, false if not. Value matching will be case-sensitive.

JWPLocateSelectValue(myForm.mySelect, "opt1", true, true);
This will again find the value, if present, but will do so without regard for case (i.e., opt1 == OPT1).

Author:
Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String renderScriptTags
          Whether to render the opening and closing script tags around the emitted Javascript.
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
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
LocateSelectValueTag()
           
 
Method Summary
 int doStartTag()
          Render the results of the tag.
 void setRenderScriptTags(java.lang.String inRenderScriptTags)
          renderScriptTags mutator.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


renderScriptTags

private java.lang.String renderScriptTags
Whether to render the opening and closing script tags around the emitted Javascript.

Constructor Detail

LocateSelectValueTag

public LocateSelectValueTag()
Method Detail

setRenderScriptTags

public void setRenderScriptTags(java.lang.String inRenderScriptTags)
renderScriptTags mutator.

Parameters:
inRenderScriptTags - renderScriptTags.

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the results of the tag.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Return code.
Throws:
javax.servlet.jsp.JspException - If anything goes wrong


Copyright © 2005 Frank W. Zammetti