01: /*
02: * $Id: Label.java 497654 2007-01-19 00:21:57Z rgielen $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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" + " read-only information")
57: public class Label extends UIBean {
58: final public static String TEMPLATE = "label";
59:
60: protected String forAttr;
61:
62: public Label(ValueStack stack, HttpServletRequest request,
63: 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: // try value first, then name (this overrides the default behavior in the superclass)
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: }
|