org.rhq.enterprise.gui.legacy.taglib
Class ConstantsTag
java.lang.Object
javax.servlet.jsp.tagext.TagSupport
org.rhq.enterprise.gui.legacy.taglib.ConstantsTag
- All Implemented Interfaces:
- 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
- Author:
- Hyperic, Ian Springer (added support for Enums)
- 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 |
| 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 Map constants
constantsClassNameParam
public static final String constantsClassNameParam
- See Also:
- Constant Field Values
ConstantsTag
public ConstantsTag()
setClassname
public void setClassname(String aClass)
getClassname
public String getClassname()
setVar
public void setVar(String aVar)
getVar
public String getVar()
setFailmode
public void setFailmode(boolean theFailmode)
getFailmode
public boolean getFailmode()
setSymbol
public void setSymbol(String aSymbol)
getSymbol
public String getSymbol()
setScope
public void setScope(String aScopeName)
getScope
public 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(Map fieldMap,
javax.servlet.jsp.JspWriter out)
throws IOException
- Throws:
IOException
doSet
protected void doSet(Map fieldMap)
validate
protected boolean validate(javax.servlet.jsp.JspWriter out)
throws javax.servlet.jsp.JspException
- 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,
String err)
throws javax.servlet.jsp.JspException
- Throws:
javax.servlet.jsp.JspException
Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.