View Javadoc

1   /*
2    * $Id: IteratorTag.java 741179 2009-02-05 16:55:14Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.views.jsp;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  import javax.servlet.jsp.JspException;
27  
28  import org.apache.struts2.components.Component;
29  import org.apache.struts2.components.IteratorComponent;
30  
31  import com.opensymphony.xwork2.util.ValueStack;
32  
33  /***
34   * @see IteratorComponent
35   */
36  public class IteratorTag extends ContextBeanTag {
37  
38      private static final long serialVersionUID = -1827978135193581901L;
39  
40      protected String statusAttr;
41      protected String value;
42      protected String begin;
43      protected String end;
44      protected String step;
45  
46      public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
47          return new IteratorComponent(stack);
48      }
49  
50      protected void populateParams() {
51          super.populateParams();
52  
53          IteratorComponent tag = (IteratorComponent) getComponent();
54          tag.setStatus(statusAttr);
55          tag.setValue(value);
56          tag.setBegin(begin);
57          tag.setEnd(end);
58          tag.setStep(step);
59      }
60  
61      public void setStatus(String status) {
62          this.statusAttr = status;
63      }
64  
65      public void setValue(String value) {
66          this.value = value;
67      }
68  
69      public void setBegin(String begin) {
70          this.begin = begin;
71      }
72  
73      public void setEnd(String end) {
74          this.end = end;
75      }
76  
77      public void setStep(String step) {
78          this.step = step;
79      }
80  
81      public int doEndTag() throws JspException {
82          component = null;
83          return EVAL_PAGE;
84      }
85  
86      public int doAfterBody() throws JspException {
87          boolean again = component.end(pageContext.getOut(), getBody());
88  
89          if (again) {
90              return EVAL_BODY_AGAIN;
91          } else {
92              if (bodyContent != null) {
93                  try {
94                      bodyContent.writeOut(bodyContent.getEnclosingWriter());
95                  } catch (Exception e) {
96                      throw new JspException(e.getMessage());
97                  }
98              }
99              return SKIP_BODY;
100         }
101     }
102 
103 }