org.hyperic.hq.ui.taglib
Class ConstantsTag
java.lang.Object
javax.servlet.jsp.tagext.TagSupport
org.hyperic.hq.ui.taglib.ConstantsTag
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag
- Direct Known Subclasses:
- ConstantsDiagTag
public class ConstantsTag
- extends javax.servlet.jsp.tagext.TagSupport
A sensible way to handle constants in a webapp is to define a bean that
holds all of the constants as attributes. However, Java programmers have a
propensity for creating constants as classes that have the values defined
static final members. This tag exposes these attribute handles to save the
developer from having to read the constants class source code to determine
the returned values. This way the JSP source and the backend bean (and/or
bean handlers) have a consistent interface to the constants class.
Under the hood, the tag uses reflection to build a map of names and values.
The map is cached to save the expense of repeated runtime reflection.
Usage:
Suppose you have a class com.example.Constants:
public class Constants {
public static final int WARMRESTART = 0;
public static final int COLDRESTART = 1;
public static final int HARDRESTART = 2;
public static final String RO = "rock";
public static final String SHAM = "paper";
public static final String BO = "scissors";
}
and you want to uniformly access the symbold names in the
jsp as you would in your Java classes. Use this tag.
<%@ taglib uri="/WEB-INF/constants.tld" prefix="constants" %>
... someplace where a constant needs to be accessed:
Important: This usage assumes the class to access is specified in a
web-xml/context-param
The alternate form
can be used to accomadate having multiple constants classes.
Another usage is set attributes, within an optionally specified scope
or just
to put it in the page scope.
Either way, at sometime later, you can do this
- See Also:
- Serialized Form
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 |
Method Summary |
protected void |
die(javax.servlet.jsp.JspWriter out)
|
protected void |
die(javax.servlet.jsp.JspWriter out,
java.lang.String err)
|
int |
doEndTag()
|
protected void |
doOutput(java.util.HashMap fieldMap,
javax.servlet.jsp.JspWriter out)
|
protected void |
doSet(java.util.HashMap fieldMap)
|
java.lang.String |
getClassname()
|
boolean |
getFailmode()
|
java.lang.String |
getScope()
|
java.lang.String |
getSymbol()
|
java.lang.String |
getVar()
|
void |
release()
|
void |
setClassname(java.lang.String aClass)
|
void |
setFailmode(boolean theFailmode)
|
void |
setScope(java.lang.String aScopeName)
|
void |
setSymbol(java.lang.String aSymbol)
|
void |
setVar(java.lang.String aVar)
|
protected boolean |
validate(javax.servlet.jsp.JspWriter out)
Method validate
Checks for broken configuration/attribute combinations |
Methods inherited from class javax.servlet.jsp.tagext.TagSupport |
doAfterBody, doStartTag, 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 |
constants
protected static java.util.HashMap constants
constantsClassNameParam
public static final java.lang.String constantsClassNameParam
- See Also:
- Constant Field Values
ConstantsTag
public ConstantsTag()
setClassname
public void setClassname(java.lang.String aClass)
getClassname
public java.lang.String getClassname()
setVar
public void setVar(java.lang.String aVar)
getVar
public java.lang.String getVar()
setFailmode
public void setFailmode(boolean theFailmode)
getFailmode
public boolean getFailmode()
setSymbol
public void setSymbol(java.lang.String aSymbol)
getSymbol
public java.lang.String getSymbol()
setScope
public void setScope(java.lang.String aScopeName)
getScope
public java.lang.String getScope()
release
public void release()
- Specified by:
release
in interface javax.servlet.jsp.tagext.Tag
- Overrides:
release
in class javax.servlet.jsp.tagext.TagSupport
doEndTag
public int doEndTag()
throws javax.servlet.jsp.JspException
- Specified by:
doEndTag
in interface javax.servlet.jsp.tagext.Tag
- Overrides:
doEndTag
in class javax.servlet.jsp.tagext.TagSupport
- Throws:
javax.servlet.jsp.JspException
doOutput
protected void doOutput(java.util.HashMap fieldMap,
javax.servlet.jsp.JspWriter out)
throws java.io.IOException
- Throws:
java.io.IOException
doSet
protected void doSet(java.util.HashMap fieldMap)
validate
protected boolean validate(javax.servlet.jsp.JspWriter out)
throws javax.servlet.jsp.JspException
- Method validate
Checks for broken configuration/attribute combinations
- Returns:
- true is validation fails
- Throws:
javax.servlet.jsp.JspException
die
protected void die(javax.servlet.jsp.JspWriter out)
throws javax.servlet.jsp.JspException
- Throws:
javax.servlet.jsp.JspException
die
protected void die(javax.servlet.jsp.JspWriter out,
java.lang.String err)
throws javax.servlet.jsp.JspException
- Throws:
javax.servlet.jsp.JspException
Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.