KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > nested > NestedRootTag


1 /*
2  * $Id: NestedRootTag.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.struts.taglib.nested;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
23
24 import org.apache.struts.taglib.TagUtils;
25
26 /**
27  * NestedRootTag.
28  *
29  * The only other addition in this nested suite of tags.
30  * This tag allows for a nested structure to start without relying on the bean
31  * and workings of the FormTag. Useful for view pages that don't update when
32  * returning to the 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 the
39  * nesting list.
40  *
41  * @since Struts 1.1
42  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
43  */

44 public class NestedRootTag extends BodyTagSupport JavaDoc implements NestedNameSupport {
45
46   /** Getter method for the <i>property</i> property
47    * @return String value of the property property
48    */

49   public String JavaDoc getProperty() {
50     return "";
51   }
52   /** Setter method for the <i>property</i> property
53    * @param property new value for the property property
54    */

55   public void setProperty(String JavaDoc property) {}
56
57   /** Getter method for the <i>name</i> property
58    * @return String value of the name property
59    */

60   public String JavaDoc getName() {
61     return this.name;
62   }
63   /** Setter method for the <i>name</i> property
64    * @param name new value for the name property
65    */

66   public void setName(String JavaDoc name) {
67     this.name = name;
68   }
69
70   /**
71    * Overriding method of the heart of the tag. Gets the relative property
72    * and tells the JSP engine to evaluate its body content.
73    *
74    * @return int JSP continuation directive.
75    */

76   public int doStartTag() throws JspException JavaDoc {
77     /* set the nested reference for possible inclusions etc */
78     HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
79
80     // get al the originals
81
originalName = name;
82     originalNesting = NestedPropertyHelper.getCurrentProperty(request);
83     originalNestingName = NestedPropertyHelper.getCurrentName(request, this);
84
85     // set what we have to
86
if (name != null) {
87       NestedPropertyHelper.setProperty(request, "");
88       NestedPropertyHelper.setName(request, this.name);
89     }
90
91     // do the JSP thing
92
return (EVAL_BODY_TAG);
93   }
94
95   /**
96    * Render the resulting content evaluation.
97    *
98    * @return int JSP continuation directive.
99    */

100   public int doAfterBody() throws JspException JavaDoc {
101     /* Render the output */
102     if (bodyContent != null) {
103       TagUtils.getInstance().writePrevious(pageContext, bodyContent.getString());
104       bodyContent.clearBody();
105     }
106
107     return (SKIP_BODY);
108   }
109
110   /**
111    * Evaluate the rest of the page
112    *
113    * @return int JSP continuation directive.
114    */

115   public int doEndTag() throws JspException JavaDoc {
116     /* reset the reference */
117     HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
118
119     if (originalNesting == null) {
120       NestedPropertyHelper.deleteReference(request);
121     } else {
122       NestedPropertyHelper.setName(request, originalNestingName);
123       NestedPropertyHelper.setProperty(request, originalNesting);
124     }
125     this.name = originalName;
126
127     return (EVAL_PAGE);
128   }
129
130
131   /**
132    * JSP method to release all resources held by the tag.
133    */

134   public void release() {
135     super.release();
136     this.name = null;
137     this.originalName = null;
138     this.originalNesting = null;
139     this.originalNestingName = null;
140   }
141
142   /* usual member variables */
143   private String JavaDoc name = null;
144   private String JavaDoc originalName = "";
145   private String JavaDoc originalNesting = "";
146   private String JavaDoc originalNestingName = "";
147 }
148
Popular Tags