1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.taglib.html;
22
23 import org.apache.struts.util.MessageResources;
24
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.BodyTagSupport;
27 import javax.servlet.jsp.tagext.Tag;
28
29 /**
30 * Adds a new request parameter to its parent {@link LinkTag}.
31 *
32 * @version $Rev: 482912 $ $Date: 2006-12-05 23:48:32 -0600 (Tue, 05 Dec 2006) $
33 * @since Struts 1.3.6
34 */
35 public class ParamTag extends BodyTagSupport {
36
37 /**
38 * The message resources for this package.
39 */
40 protected static MessageResources messages =
41 MessageResources.getMessageResources(Constants.Package
42 + ".LocalStrings");
43
44 /**
45 * The name of the query parameter.
46 */
47 protected String name = null;
48
49 /**
50 * The value of the query parameter or body content of this tag (if any).
51 */
52 protected String value = null;
53
54
55
56 public ParamTag() {
57 super();
58 }
59
60 public String getName() {
61 return (this.name);
62 }
63
64 public void setName(String name) {
65 this.name = name;
66 }
67
68 public String getValue() {
69 return (this.value);
70 }
71
72 public void setValue(String value) {
73 this.value = value;
74 }
75
76
77
78 /**
79 * @throws JspException if a JSP exception has occurred
80 */
81 public int doStartTag() throws JspException {
82 return (EVAL_BODY_TAG);
83 }
84
85 /**
86 * Save the associated from the body content.
87 *
88 * @throws JspException if a JSP exception has occurred
89 */
90 public int doAfterBody() throws JspException {
91 if (this.bodyContent != null) {
92 String value = this.bodyContent.getString().trim();
93 if (value.length() > 0) {
94 this.value = value;
95 }
96 }
97 return (SKIP_BODY);
98 }
99
100 /**
101 * Render the end of the hyperlink.
102 *
103 * @throws JspException if a JSP exception has occurred
104 */
105 public int doEndTag() throws JspException {
106 Tag tag = findAncestorWithClass(this, LinkTag.class);
107 if (tag != null) {
108 ((LinkTag)tag).addParameter(this.name, this.value);
109 } else {
110 throw new JspException(messages.getMessage("linkParamTag.linkParam"));
111 }
112 return (EVAL_PAGE);
113 }
114
115 /**
116 * Release any acquired resources.
117 */
118 public void release() {
119 super.release();
120 this.name = null;
121 this.value = null;
122 }
123 }