View Javadoc

1   package mx.com.brained.taglib;
2   
3   import javax.servlet.jsp.*;
4   import javax.servlet.jsp.tagext.*;
5   
6   
7   import org.apache.struts.Globals;
8   import org.apache.struts.taglib.TagUtils;
9   import java.util.*;
10  
11  /***
12   *
13   * @author Isidoro Treviņo, Eliseo Partida
14   * @version 1.0
15   * @jsp.tag
16   *   name="gridElement"
17   *   body-content="empty"
18   *   description="Tag that renders a grid column"
19   *
20   */
21  public class GridElement extends TagSupport {
22  
23      protected String name;
24      protected String property;
25      protected String title;
26      protected String type = GridConstants.READONLY;
27      protected String bundle;
28      protected String locale = Globals.LOCALE_KEY;
29  
30      /***
31       * This method renders the grid element based on the properties set
32       * @return int
33       * @throws JspException
34       */
35      public int doStartTag() throws JspException {
36          Tag tag = this.getParent();
37          GridIteratorTag parent;
38          GridUtil util;
39          if (tag != null && tag instanceof GridIteratorTag) {
40              parent = (GridIteratorTag) tag;
41              util = parent.getGridUtil();
42              if (parent.getIndex() == 0) {
43                  String message =
44                          TagUtils.getInstance().message(
45                                  pageContext,
46                                  this.bundle,
47                                  locale,
48                                  title,
49                                  null);
50                  HashMap map = new HashMap();
51                  map.put(GridConstants.HEADER,message);
52                  map.put(GridConstants.PROPERTY,property);
53                  map.put(GridConstants.TYPE,type);
54                  util.addTitle(map);
55              }
56              Object value = null;
57              try {
58                  value = TagUtils.getInstance().lookup(pageContext, name,
59                          property, null);
60              } catch (Exception ex) {
61                  util.setEmptyCollection();
62                  value=null;
63              }
64              if(value!=null){
65                  util.setData(value.toString());
66              }
67              else{
68                  util.setData("");
69              }
70          }
71          return this.SKIP_BODY;
72      }
73  
74      public GridElement() {
75      }
76      /***
77       * Set the name of the bean containing the value to be rendered
78       * @param name String
79       */
80      public void setName(String name) {
81          this.name = name;
82      }
83      /***
84       * Set the property of the bean rendered as a grid element
85       * @param property String
86       */
87      public void setProperty(String property) {
88          this.property = property;
89      }
90      /***
91       * Set the resource bundle key to be rendered as the header
92       * @param title String
93       */
94      public void setTitle(String title) {
95          this.title = title;
96      }
97      /***
98       * Sets the type of element to be rendered, must be one of the following:
99       * <ul>
100      * <li>readonly</li>
101      * <li>editable</li>
102      * <li>date</li>
103      * </ul>
104      * @param type String
105      */
106     public void setType(String type) {
107         this.type = type;
108     }
109     /***
110      * Set the locale to be rendered
111      * @param locale String
112      */
113     public void setLocale(String locale) {
114         this.locale = locale;
115     }
116     /***
117      * Set the bundle to which the key belongs to
118      * @param bundle String
119      */
120     public void setBundle(String bundle) {
121         this.bundle = bundle;
122     }
123 
124     /***
125      * Returns the name of the bean containing the value to be rendered
126      * @return String
127      * @jsp.attribute
128      *    required="true"
129      *    rtexprvalue="false"
130      */
131     public String getName() {
132         return name;
133     }
134 
135     /***
136      * Return the property of the bean rendered as a combobox
137      * @return String
138      * @jsp.attribute
139      *    required="true"
140      *    rtexprvalue="false"
141      *
142      */
143     public String getProperty() {
144         return property;
145     }
146 
147     /***
148      * Return the resource bundle key to be rendered as the header
149      * @return String
150      * @jsp.attribute
151      *    required="true"
152      *    rtexprvalue="false"
153      *
154      */
155     public String getTitle() {
156         return title;
157     }
158 
159     /***
160      * Get the type of element to be rendered
161      * @return String
162      * @jsp.attribute
163      *    required="false"
164      *    rtexprvalue="false"
165      */
166     public String getType() {
167         return type;
168     }
169 
170 
171     /***
172      * Return the locale that was set
173      * @return String
174      * @jsp.attribute
175      *    required="false"
176      *    rtexprvalue="false"
177      */
178     public String getLocale() {
179         return locale;
180     }
181 
182     /***
183      * Return the bundle to which the key belongs to
184      * @return String
185      * @jsp.attribute
186      *    required="false"
187      *    rtexprvalue="false"
188      */
189     public String getBundle() {
190         return bundle;
191     }
192     /***
193      * Reset the properties to be reused
194      */
195     public void release(){
196         name=null;
197         property=null;
198         title=null;
199         type = GridConstants.READONLY;
200         bundle=null;
201         locale = Globals.LOCALE_KEY;
202     }
203 }