View Javadoc

1   /*
2    * $Id: NestedOptionsTag.java 376843 2006-02-10 21:02:56Z husted $
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.Constants;
21  import org.apache.struts.taglib.html.OptionsTag;
22  import org.apache.struts.taglib.nested.NestedNameSupport;
23  import org.apache.struts.taglib.nested.NestedPropertyHelper;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.jsp.JspException;
27  
28  /***
29   * NestedOptionsTag.
30   *
31   * @version $Rev: 376843 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
32   *          $
33   * @since Struts 1.1
34   */
35  public class NestedOptionsTag extends OptionsTag implements NestedNameSupport {
36      /* the usual private member variables */
37      private String originalName = null;
38      private String originalProperty = null;
39      private String originalLabelProperty = null;
40  
41      /***
42       * Overriding method of the heart of the matter. Gets the relative
43       * property and leaves the rest up to the original tag implementation.
44       * Sweet.
45       *
46       * @return int JSP continuation directive. This is in the hands of the
47       *         super class.
48       */
49      public int doStartTag() throws JspException {
50          // get the original properties
51          originalName = getName();
52          originalProperty = getProperty();
53          originalLabelProperty = getLabelProperty();
54  
55          // request
56          HttpServletRequest request =
57              (HttpServletRequest) pageContext.getRequest();
58  
59          // if we have a label property
60          if (originalLabelProperty != null) {
61              // do the label property first
62              if ((getName() == null) || Constants.BEAN_KEY.equals(getName())) {
63                  super.setLabelProperty(NestedPropertyHelper.getAdjustedProperty(
64                          request, originalLabelProperty));
65              } else {
66                  super.setLabelProperty(originalLabelProperty);
67              }
68          }
69  
70          // set the other properties
71          NestedPropertyHelper.setNestedProperties(request, this);
72  
73          // let the super do it's thing
74          return super.doStartTag();
75      }
76  
77      /***
78       * Complete the processing of the tag. The nested tags here will restore
79       * all the original value for the tag itself and the nesting context.
80       *
81       * @return int to describe the next step for the JSP processor
82       * @throws JspException for the bad things JSP's do
83       */
84      public int doEndTag() throws JspException {
85          // do the super's ending part
86          int i = super.doEndTag();
87  
88          // reset the properties
89          setName(originalName);
90          setProperty(originalProperty);
91          setLabelProperty(originalLabelProperty);
92  
93          // continue
94          return i;
95      }
96  
97      /***
98       * Release the tag's resources and reset the values.
99       */
100     public void release() {
101         super.release();
102 
103         // reset the originals
104         originalName = null;
105         originalProperty = null;
106         originalLabelProperty = null;
107     }
108 }