View Javadoc

1   /*
2    * $Id: NestedFormTag.java 421129 2006-07-12 05:13:54Z wsmoak $
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.html;
19  
20  import org.apache.struts.taglib.html.FormTag;
21  import org.apache.struts.taglib.nested.NestedNameSupport;
22  import org.apache.struts.taglib.nested.NestedPropertyHelper;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.jsp.JspException;
26  
27  /***
28   * NestedFormTag.
29   *
30   * @version $Rev: 421129 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
31   *          $
32   * @since Struts 1.1
33   */
34  public class NestedFormTag extends FormTag implements NestedNameSupport {
35      //TODO: name property was removed from FormTag but appears to be required
36      //      for the nested version to work. See if it can be removed
37      //      from here altogether.
38  
39      /***
40       * The name
41       */
42      protected String name = null;
43  
44      // original nesting environment
45      private String originalNesting = null;
46      private String originalNestingName = null;
47  
48      /***
49       * Return the name.
50       */
51      public String getName() {
52          return (this.name);
53      }
54  
55      /***
56       * Set the name.
57       *
58       * @param name The new name
59       */
60      public void setName(String name) {
61          this.name = name;
62      }
63  
64      /***
65       * Get the string value of the "property" property.
66       *
67       * @return the property property
68       */
69      public String getProperty() {
70          return "";
71      }
72  
73      /***
74       * Setter for the "property" property
75       *
76       * @param newProperty new value for the property
77       */
78      public void setProperty(String newProperty) {
79      }
80  
81      /***
82       * Overriding to allow the chance to set the details of the system, so
83       * that dynamic includes can be possible
84       *
85       * @return int JSP continuation directive.
86       */
87      public int doStartTag() throws JspException {
88          // store original result
89          int temp = super.doStartTag();
90  
91          HttpServletRequest request =
92              (HttpServletRequest) pageContext.getRequest();
93  
94          // original nesting details
95          originalNesting = NestedPropertyHelper.getCurrentProperty(request);
96          originalNestingName =
97              NestedPropertyHelper.getCurrentName(request, this);
98  
99          // some new details
100         NestedPropertyHelper.setProperty(request, null);
101         NestedPropertyHelper.setName(request, super.getBeanName());
102 
103         // continue
104         return temp;
105     }
106 
107     /***
108      * This is only overriden to clean up the include reference
109      *
110      * @return int JSP continuation directive.
111      */
112     public int doEndTag() throws JspException {
113         // super result
114         int temp = super.doEndTag();
115 
116         // all done. clean up
117         HttpServletRequest request =
118             (HttpServletRequest) pageContext.getRequest();
119 
120         // reset the original nesting values
121         if (originalNesting == null) {
122             NestedPropertyHelper.deleteReference(request);
123         } else {
124             NestedPropertyHelper.setProperty(request, originalNesting);
125             NestedPropertyHelper.setName(request, originalNestingName);
126         }
127 
128         // return the super result
129         return temp;
130     }
131 
132     /***
133      * Release the tag's resources and reset the values.
134      */
135     public void release() {
136         // let the super release
137         super.release();
138 
139         // reset the original value place holders
140         originalNesting = null;
141         originalNestingName = null;
142     }
143 }