01: package com.opensymphony.webwork.components;
02:
03: import com.opensymphony.xwork.util.OgnlValueStack;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: /**
09: * <!-- START SNIPPET: javadoc -->
10: * Renders an HTML LABEL that will allow you to output label:name combination that has the same format treatment as
11: * the rest of your UI controls.</p>
12: * <!-- END SNIPPET: javadoc -->
13: *
14: * <p/> <b>Examples</b>
15: * <p/>
16: * <!-- START SNIPPET: exdescription -->
17: * In this example, a label is rendered. The label is retrieved from a ResourceBundle by calling ActionSupport's
18: * getText() method giving you an output of 'User Name:tm_jee'. Assuming that i18n message user_name corresponds
19: * to 'User Name' and the action's getUserName() method returns 'tm_jee'<p/>
20: * <!-- END SNIPPET: exdescription -->
21: * <pre>
22: * <!-- START SNIPPET: example -->
23: * <ww:label label="%{text('user_name')}" name="userName" />
24: * <!-- END SNIPPET: example -->
25: * </pre>
26: *
27: * @author Patrick Lightbody
28: * @author Rene Gielen
29: * @version $Revision: 2468 $
30: * @since 2.2
31: *
32: * @ww.tag name="label" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.LabelTag"
33: * description="Render a label that displays read-only information"
34: */
35: public class Label extends UIBean {
36: final public static String TEMPLATE = "label";
37:
38: protected String forAttr;
39:
40: public Label(OgnlValueStack stack, HttpServletRequest request,
41: HttpServletResponse response) {
42: super (stack, request, response);
43: }
44:
45: protected String getDefaultTemplate() {
46: return TEMPLATE;
47: }
48:
49: protected void evaluateExtraParams() {
50: super .evaluateExtraParams();
51:
52: if (forAttr != null) {
53: addParameter("for", findString(forAttr));
54: }
55:
56: // try value first, then name (this overrides the default behavior in the superclass)
57: if (value != null) {
58: addParameter("nameValue", findString(value));
59: } else if (name != null) {
60: String expr = name;
61: if (altSyntax()) {
62: expr = "%{" + expr + "}";
63: }
64:
65: addParameter("nameValue", findString(expr));
66: }
67: }
68:
69: /**
70: * HTML for attribute
71: * @ww.tagattribute required="false"
72: */
73: public void setFor(String forAttr) {
74: this.forAttr = forAttr;
75: }
76: }
|