1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components;
22
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.apache.struts2.views.annotations.StrutsTag;
27 import org.apache.struts2.views.annotations.StrutsTagAttribute;
28
29 import com.opensymphony.xwork2.util.ValueStack;
30
31 /***
32 * <!-- START SNIPPET: javadoc -->
33 * Renders an HTML LABEL that will allow you to output label:name combination that has the same format treatment as
34 * the rest of your UI controls.</p>
35 * <!-- END SNIPPET: javadoc -->
36 *
37 * <p/> <b>Examples</b>
38 * <p/>
39 * <!-- START SNIPPET: exdescription -->
40 * In this example, a label is rendered. The label is retrieved from a ResourceBundle via the key attribute
41 * giving you an output of 'User Name: Ford.Prefect'. Assuming that i18n message userName corresponds
42 * to 'User Name' and the action's getUserName() method returns 'Ford.Prefect'<p/>
43 * <!-- END SNIPPET: exdescription -->
44 * <pre>
45 * <!-- START SNIPPET: example -->
46 * <s:label key="userName" />
47 * <!-- END SNIPPET: example -->
48 * </pre>
49 * <pre>
50 * <!-- START SNIPPET: example2 -->
51 * <s:label name="userName" label="User Name" />
52 * <!-- END SNIPPET: example -->
53 * </pre>
54 *
55 */
56 @StrutsTag(name="label", tldTagClass="org.apache.struts2.views.jsp.ui.LabelTag", description="Render a label that displays" +
57 " read-only information")
58 public class Label extends UIBean {
59 final public static String TEMPLATE = "label";
60
61 protected String forAttr;
62
63 public Label(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
64 super(stack, request, response);
65 }
66
67 protected String getDefaultTemplate() {
68 return TEMPLATE;
69 }
70
71 protected void evaluateExtraParams() {
72 super.evaluateExtraParams();
73
74 if (forAttr != null) {
75 addParameter("for", findString(forAttr));
76 }
77
78
79 if (value != null) {
80 addParameter("nameValue", findString(value));
81 } else if (name != null) {
82 String expr = name;
83 if (altSyntax()) {
84 expr = "%{" + expr + "}";
85 }
86
87 addParameter("nameValue", findString(expr));
88 }
89 }
90
91 @StrutsTagAttribute(description=" HTML for attribute")
92 public void setFor(String forAttr) {
93 this.forAttr = forAttr;
94 }
95 }