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