KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > albel > tags > table > TableTag


1 package albel.tags.table;
2
3 import javax.servlet.jsp.*;
4 import javax.servlet.*;
5 import javax.servlet.jsp.tagext.*;
6 import javax.servlet.http.*;
7 import albel.tags.table.utils.*;
8 import albel.tags.table.model.*;
9 import albel.tags.table.render.*;
10 import albel.tags.table.controll.*;
11 /**
12  * @author albel
13  *Tag that defines core of this package - Table
14  */

15 public class TableTag extends BodyTagSupport
16 {
17     
18     /**
19      * Id of the table. Must be unique in current users session.
20      */

21     private String JavaDoc id;
22     
23     /**
24      * Bean class, that acts as the source of the table data
25      */

26     private String JavaDoc sourceBeanClass;
27     
28     /**
29      * Holds value of property language.
30      */

31     private String JavaDoc language;
32     
33     /**
34      * Holds value of property country.
35      */

36     private String JavaDoc country;
37     
38     public TableTag()
39     {
40         super();
41     }
42     
43     
44     ////////////////////////////////////////////////////////////////
45
/// ///
46
/// User methods. ///
47
/// ///
48
/// Modify these methods to customize your tag handler. ///
49
/// ///
50
////////////////////////////////////////////////////////////////
51

52     
53     //
54
// methods called from doStartTag()
55
//
56
/**
57      *
58      * Fill in this method to perform other operations from doStartTag().
59      *
60      */

61     public void otherDoStartTagOperations()
62     {
63         
64         //
65
// TODO: code that performs other operations in doStartTag
66
// should be placed here.
67
// It will be called after initializing variables,
68
// finding the parent, setting IDREFs, etc, and
69
// before calling theBodyShouldBeEvaluated().
70
//
71
// For example, to print something out to the JSP, use the following:
72
//
73
// try {
74
// JspWriter out = pageContext.getOut();
75
// out.println("something");
76
// } catch (java.io.IOException ex) {
77
// // do something
78
// }
79
//<tt:Column property="name" />
80
//
81

82         
83     }
84     
85     /**
86      *
87      * Fill in this method to determine if the tag body should be evaluated
88      * Called from doStartTag().
89      *
90      */

91     public boolean theBodyShouldBeEvaluated()
92     {
93         
94         //
95
// TODO: code that determines whether the body should be
96
// evaluated should be placed here.
97
// Called from the doStartTag() method.
98
//
99
return true;
100         
101     }
102     
103     
104     //
105
// methods called from doEndTag()
106
//
107
/**
108      *
109      * Fill in this method to perform other operations from doEndTag().
110      *
111      */

112     public void otherDoEndTagOperations()
113     {
114         
115         //
116
// TODO: code that performs other operations in doEndTag
117
// should be placed here.
118
// It will be called after initializing variables,
119
// finding the parent, setting IDREFs, etc, and
120
// before calling shouldEvaluateRestOfPageAfterEndTag().
121
//
122

123         
124     }
125     
126     /**
127      *
128      * Fill in this method to determine if the rest of the JSP page
129      * should be generated after this tag is finished.
130      * Called from doEndTag().
131      *
132      */

133     public boolean shouldEvaluateRestOfPageAfterEndTag()
134     {
135         
136         //
137
// TODO: code that determines whether the rest of the page
138
// should be evaluated after the tag is processed
139
// should be placed here.
140
// Called from the doEndTag() method.
141
//
142
return true;
143         
144     }
145     
146     
147     ////////////////////////////////////////////////////////////////
148
/// ///
149
/// Tag Handler interface methods. ///
150
/// ///
151
/// Do not modify these methods; instead, modify the ///
152
/// methods that they call. ///
153
/// ///
154
////////////////////////////////////////////////////////////////
155

156     
157     /**
158      * Methos calls Manager to create table with given id if table does not exists yet.
159      */

160     public int doStartTag() throws JspException
161     {
162         HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
163         HttpSessionAttributesMap attrs=new HttpSessionAttributesMap(request.getSession());
164         if(!Manager.tableExists(attrs,getId()))
165         {
166             Table table=Manager.createTable(attrs, id);
167             table.setSourceBeanClass(getSourceBeanClass());
168             if(language!=null && country!=null)
169             {
170                 java.util.Locale JavaDoc loc=new java.util.Locale JavaDoc(getLanguage(),getCountry());
171                 table.setLocale(loc);
172             }
173         }
174         return this.EVAL_BODY_INCLUDE;
175     }
176     
177     
178     /**
179      * Methos handles table state, and calls table renderer, to begin rendering operation.
180      */

181     public int doEndTag() throws JspException
182     {
183         HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
184         HttpSessionAttributesMap attrsCtx=new HttpSessionAttributesMap(request.getSession());
185         Table t=Manager.getTable(attrsCtx, getId());
186         try
187         {
188             HttpRequestParametersMap reqPars=new HttpRequestParametersMap(request.getParameterMap());
189             StateController.setupTableState(t, reqPars);
190         }
191         catch (albel.tags.table.model.TableTagException tex)
192         {
193             throw new JspException(tex);
194         }
195         ITableRenderer tableRend=Manager.getTableRenderer(t);
196         String JavaDoc html=tableRend.render().getRenderable().toString();
197         Writer.write(pageContext, html);
198         //Writer.write(pageContext,"</TABLE>");
199
// Dummy body to get things going.
200
return EVAL_PAGE;
201     }
202     
203     /**
204      * Getter for property id.
205      * @return Value of property id.
206      */

207     public String JavaDoc getId()
208     {
209         return this.id;
210     }
211     
212     /**
213      * Setter for property id.
214      * @param id New value of property id.
215      */

216     public void setId(String JavaDoc id)
217     {
218         this.id = id;
219     }
220     
221     /**
222      * Getter for property sourceBeanClass.
223      * @return Value of property sourceBeanClass.
224      */

225     public String JavaDoc getSourceBeanClass()
226     {
227         return this.sourceBeanClass;
228     }
229     
230     /**
231      * Setter for property sourceBeanClass.
232      * @param sourceBeanClass New value of property sourceBeanClass.
233      */

234     public void setSourceBeanClass(String JavaDoc sourceBeanClass)
235     {
236         this.sourceBeanClass = sourceBeanClass;
237     }
238     
239     /**
240      * Getter for property language.
241      * @return Value of property language.
242      */

243     public String JavaDoc getLanguage()
244     {
245         return this.language;
246     }
247     
248     /**
249      * Setter for property language.
250      * @param language New value of property language.
251      */

252     public void setLanguage(String JavaDoc language)
253     {
254         this.language = language;
255     }
256     
257     /**
258      * Getter for property country.
259      * @return Value of property country.
260      */

261     public String JavaDoc getCountry()
262     {
263         return this.country;
264     }
265     
266     /**
267      * Setter for property country.
268      * @param country New value of property country.
269      */

270     public void setCountry(String JavaDoc country)
271     {
272         this.country = country;
273     }
274     
275 }
276
Popular Tags