1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.taglib.nested;
19
20 import org.apache.struts.taglib.TagUtils;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.tagext.BodyTagSupport;
25
26 /***
27 * NestedRootTag.
28 *
29 * The only other addition in this nested suite of tags. This tag allows for a
30 * nested structure to start without relying on the bean and workings of the
31 * FormTag. Useful for view pages that don't update when returning to the
32 * server, or use hyperlinks rather than form submits.
33 *
34 * The Bean that it uses can come out of a jsp:useBean tag or define another
35 * bean that's already in scope. As long as the other Struts tags can find the
36 * bean by name, it'll work.
37 *
38 * It's simply recognised by the helper class and it's property is added to
39 * the nesting list.
40 *
41 * @version $Rev: 376843 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
42 * $
43 * @since Struts 1.1
44 */
45 public class NestedRootTag extends BodyTagSupport implements NestedNameSupport {
46
47 private String name = null;
48 private String originalName = "";
49 private String originalNesting = "";
50 private String originalNestingName = "";
51
52 /***
53 * Getter method for the <i>property</i> property
54 *
55 * @return String value of the property property
56 */
57 public String getProperty() {
58 return "";
59 }
60
61 /***
62 * Setter method for the <i>property</i> property
63 *
64 * @param property new value for the property property
65 */
66 public void setProperty(String property) {
67 }
68
69 /***
70 * Getter method for the <i>name</i> property
71 *
72 * @return String value of the name property
73 */
74 public String getName() {
75 return this.name;
76 }
77
78 /***
79 * Setter method for the <i>name</i> property
80 *
81 * @param name new value for the name property
82 */
83 public void setName(String name) {
84 this.name = name;
85 }
86
87 /***
88 * Overriding method of the heart of the tag. Gets the relative property
89 * and tells the JSP engine to evaluate its body content.
90 *
91 * @return int JSP continuation directive.
92 */
93 public int doStartTag() throws JspException {
94
95 HttpServletRequest request =
96 (HttpServletRequest) pageContext.getRequest();
97
98
99 originalName = name;
100 originalNesting = NestedPropertyHelper.getCurrentProperty(request);
101 originalNestingName =
102 NestedPropertyHelper.getCurrentName(request, this);
103
104
105 if (name != null) {
106 NestedPropertyHelper.setProperty(request, "");
107 NestedPropertyHelper.setName(request, this.name);
108 }
109
110
111 return (EVAL_BODY_TAG);
112 }
113
114 /***
115 * Render the resulting content evaluation.
116 *
117 * @return int JSP continuation directive.
118 */
119 public int doAfterBody() throws JspException {
120
121 if (bodyContent != null) {
122 TagUtils.getInstance().writePrevious(pageContext,
123 bodyContent.getString());
124 bodyContent.clearBody();
125 }
126
127 return (SKIP_BODY);
128 }
129
130 /***
131 * Evaluate the rest of the page
132 *
133 * @return int JSP continuation directive.
134 */
135 public int doEndTag() throws JspException {
136
137 HttpServletRequest request =
138 (HttpServletRequest) pageContext.getRequest();
139
140 if (originalNesting == null) {
141 NestedPropertyHelper.deleteReference(request);
142 } else {
143 NestedPropertyHelper.setName(request, originalNestingName);
144 NestedPropertyHelper.setProperty(request, originalNesting);
145 }
146
147 this.name = originalName;
148
149 return (EVAL_PAGE);
150 }
151
152 /***
153 * JSP method to release all resources held by the tag.
154 */
155 public void release() {
156 super.release();
157 this.name = null;
158 this.originalName = null;
159 this.originalNesting = null;
160 this.originalNestingName = null;
161 }
162 }