KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > datagrid > Footer


1  /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.datagrid;
19
20 import java.io.IOException JavaDoc;
21 import java.io.StringWriter JavaDoc;
22 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.JspContext JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.beehive.netui.tags.IHtmlEvents;
28 import org.apache.beehive.netui.tags.IHtmlI18n;
29 import org.apache.beehive.netui.tags.html.HtmlConstants;
30 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
31 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
32 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
33 import org.apache.beehive.netui.tags.rendering.TFootTag;
34 import org.apache.beehive.netui.tags.rendering.TrTag;
35 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
36 import org.apache.beehive.netui.databinding.datagrid.api.rendering.StyleModel;
37 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer;
38 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
39 import org.apache.beehive.netui.util.Bundle;
40
41 /**
42  * <p>
43  * The Footer tag is used to render a table row after the data grid has rendered the
44  * header and rows regions demarcated by the {@link Header} and {@link Rows} tags respectively.
45  * The footer tag can also optionally render a &lt;tfoot&gt; HTML tag if the data grid is rendering
46  * HTML table row groups. To enable this functionality, set the {@link DataGrid#setRenderRowGroups(boolean)}
47  * attribute. The location of the footer tag inside of a data grid does not affect when its content renders.
48  * </p>
49  * <p>
50  * The attribute setters for the footer tag are used to add HTML attributes to the &lg;tfoot&gt; HTML
51  * tag. When row group rendering is disabled, attributes set here do not render.
52  * </p>
53  * <p>
54  * Because this tag renders inside of an HTML table, it by default renders an HTML
55  * &lt;tr&gt; tag to represent a table row. Table row tag rendering can be disabled using the {@link #setRenderRow(boolean)}
56  * attribute. When this is disabled, the page author is responsible for maintaining the integrity of the
57  * HTML table by writing &lt;tr&gt; tags manually or by using the {@link Row} tag. When this tag is rendering
58  * it does not produce table cells; the contents of the table row in the footer is entirely left to the
59  * page author. With row rendering disabled, it is also possible to add multiple table rows to the
60  * end of a data grid.
61  * </p>
62  * <p>
63  * The set of JSP implicit objects available to the body include:
64  * <ul>
65  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
66  * for the cell's containing data grid.</li>
67  * </ul>
68  * </p>
69  * @jsptagref.tagdescription
70  * <p>
71  * The Footer tag is used to render a table row after the data grid has rendered the
72  * header and rows regions demarcated by the {@link Header} and {@link Rows} tags respectively.
73  * The footer tag can also optionally render a &lt;tfoot&gt; HTML tag if the data grid is rendering
74  * HTML table row groups. To enable this functionality, set the {@link DataGrid#setRenderRowGroups(boolean)}
75  * attribute. The location of the footer tag inside of a data grid does not affect when its content renders.
76  * </p>
77  * <p>
78  * The attribute setters for the footer tag are used to add HTML attributes to the &lg;tfoot&gt; HTML
79  * tag. When row group rendering is disabled, attributes set here do not render.
80  * </p>
81  * <p>
82  * Because this tag renders inside of an HTML table, it by default renders an HTML
83  * &lt;tr&gt; tag to represent a table row. Table row tag rendering can be disabled using the {@link #setRenderRow(boolean)}
84  * attribute. When this is disabled, the page author is responsible for maintaining the integrity of the
85  * HTML table by writing &lt;tr&gt; tags manually or by using the {@link Row} tag. When this tag is rendering
86  * it does not produce table cells; the contents of the table row in the footer is entirely left to the
87  * page author. With row rendering disabled, it is also possible to add multiple table rows to the
88  * end of a data grid.
89  * </p>
90  * <p>
91  * The set of JSP implicit objects available to the body include:
92  * <ul>
93  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
94  * for the cell's containing data grid.</li>
95  * </ul>
96  * </p>
97  * @netui:tag name="footer" body-content="scriptless" description="Renders a footer into a NetUI data grid"
98  */

99 public class Footer
100     extends AbstractDataGridHtmlTag
101     implements IHtmlEvents, IHtmlI18n {
102
103     private boolean _renderRow = true;
104     private TFootTag.State _tfootTag = new TFootTag.State();
105
106     /**
107      * The name of this tag; this value is used for error reporting.
108      * @return the String name of this tag
109      */

110     public String JavaDoc getTagName() {
111         return "Footer";
112     }
113
114     /**
115      * Sets the onClick JavaScript event for the HTML tfoot.
116      *
117      * @param onClick the onClick event
118      * @jsptagref.attributedescription The onClick JavaScript event for the HTML tfoot.
119      * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
120      * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event for the HTML tfoot."
121      */

122     public void setOnClick(String JavaDoc onClick) {
123         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick);
124     }
125
126     /**
127      * Sets the onDblClick JavaScript event for the HTML tfoot.
128      *
129      * @param onDblClick the onDblClick event.
130      * @jsptagref.attributedescription The onDblClick JavaScript event for the HTML tfoot.
131      * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
132      * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event for the HTML tfoot."
133      */

134     public void setOnDblClick(String JavaDoc onDblClick) {
135         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick);
136     }
137
138     /**
139      * Sets the onKeyDown JavaScript event for the HTML tfoot.
140      *
141      * @param onKeyDown the onKeyDown event.
142      * @jsptagref.attributedescription The onKeyDown JavaScript event for the HTML tfoot.
143      * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
144      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event for the HTML tfoot."
145      */

146     public void setOnKeyDown(String JavaDoc onKeyDown) {
147         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown);
148     }
149
150     /**
151      * Sets the onKeyUp JavaScript event for the HTML tfoot.
152      *
153      * @param onKeyUp the onKeyUp event.
154      * @jsptagref.attributedescription The onKeyUp JavaScript event for the HTML tfoot.
155      * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
156      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event for the HTML tfoot."
157      */

158     public void setOnKeyUp(String JavaDoc onKeyUp) {
159         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp);
160     }
161
162     /**
163      * Sets the onKeyPress JavaScript event.
164      *
165      * @param onKeyPress the onKeyPress event.
166      * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML tfoot.
167      * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
168      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event for the HTML tfoot."
169      */

170     public void setOnKeyPress(String JavaDoc onKeyPress) {
171         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress);
172     }
173
174     /**
175      * Sets the onMouseDown JavaScript event for the HTML tfoot.
176      *
177      * @param onMouseDown the onMouseDown event.
178      * @jsptagref.attributedescription The onMouseDown JavaScript event for the HTML tfoot.
179      * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
180      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event for the HTML tfoot."
181      */

182     public void setOnMouseDown(String JavaDoc onMouseDown) {
183         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown);
184     }
185
186     /**
187      * Sets the onMouseUp JavaScript event for the HTML tfoot.
188      *
189      * @param onMouseUp the onMouseUp event.
190      * @jsptagref.attributedescription The onMouseUp JavaScript event for the HTML tfoot.
191      * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
192      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event for the HTML tfoot."
193      */

194     public void setOnMouseUp(String JavaDoc onMouseUp) {
195         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp);
196     }
197
198     /**
199      * Sets the onMouseMove JavaScript event for the HTML tfoot.
200      *
201      * @param onMouseMove the onMouseMove event.
202      * @jsptagref.attributedescription The onMouseMove JavaScript event for the HTML tfoot.
203      * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
204      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event for the HTML tfoot."
205      */

206     public void setOnMouseMove(String JavaDoc onMouseMove) {
207         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove);
208     }
209
210     /**
211      * Sets the onMouseOut JavaScript event for the HTML tfoot.
212      *
213      * @param onMouseOut the onMouseOut event.
214      * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML tfoot.
215      * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
216      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event for the HTML tfoot."
217      */

218     public void setOnMouseOut(String JavaDoc onMouseOut) {
219         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut);
220     }
221
222     /**
223      * Sets the onMouseOver JavaScript event for the HTML tfoot.
224      *
225      * @param onMouseOver the onMouseOver event.
226      * @jsptagref.attributedescription The onMouseOver JavaScript event for the HTML tfoot.
227      * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
228      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event for the HTML tfoot."
229      */

230     public void setOnMouseOver(String JavaDoc onMouseOver) {
231         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver);
232     }
233
234     /**
235      * Sets the style of the HTML tfoot tag.
236      *
237      * @param style the style
238      * @jsptagref.attributedescription The style for the HTML tfoot tag.
239      * @jsptagref.attributesyntaxvalue <i>string_style</i>
240      * @netui:attribute required="false" rtexprvalue="true" description="The style for the HTML tfoot tag."
241      */

242     public void setStyle(String JavaDoc style) {
243         if("".equals(style)) return;
244
245         _tfootTag.style = style;
246     }
247
248     /**
249      * Sets the style class of the rendered html tag.
250      *
251      * @param styleClass the style class
252      * @jsptagref.attributedescription The style class of the HTML tfoot tag.
253      * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
254      * @netui:attribute required="false" rtexprvalue="true" description="The style class of the HTML tfoot tag."
255      */

256     public void setStyleClass(String JavaDoc styleClass) {
257         if("".equals(styleClass)) return;
258
259         _tfootTag.styleClass = styleClass;
260     }
261
262     /**
263      * Sets the value of the title attribute of the HTML tfoot tag.
264      *
265      * @param title
266      * @jsptagref.attributedescription The title of the HTML tfoot tag.
267      * @jsptagref.attributesyntaxvalue <i>string_title</i>
268      * @netui:attribute required="false" rtexprvalue="true" description="The title of the HTML tfoot tag."
269      */

270     public void setTitle(String JavaDoc title) {
271         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title);
272     }
273
274     /**
275      * Sets the value of the horizontal align attribute of the HTML tfoot tag.
276      *
277      * @param align the alignment
278      * @jsptagref.attributedescription The horizontal alignment of the HTML tfoot tag.
279      * @jsptagref.attributesyntaxvalue <i>string_align</i>
280      * @netui:attribute required="false" rtexprvalue="true" description="The cell's horizontal alignment of the HTML tfoot tag"
281      */

282     public void setAlign(String JavaDoc align) {
283         /* todo: should this enforce left|center|right|justify|char as in the spec? */
284         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALIGN, align);
285     }
286
287     /**
288      * Sets the value of the horizontal alignment character attribute of the HTML tfoot tag.
289      *
290      * @param alignChar the alignment character
291      * @jsptagref.attributedescription The horizontal alignment character of the HTML tfoot tag
292      * @jsptagref.attributesyntaxvalue <i>string_alignChar</i>
293      * @netui:attribute required="false" rtexprvalue="true" description="The cell's horizontal alignment character of the HTML tfoot tag"
294      */

295     public void setChar(String JavaDoc alignChar) {
296         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAR, alignChar);
297     }
298
299     /**
300      * Sets the value of the horizontal alignment character offset attribute of the HTML tfoot tag
301      *
302      * @param alignCharOff the character alignment offset
303      * @jsptagref.attributedescription The horizontal alignment character offset of the HTML tfoot tag.
304      * @jsptagref.attributesyntaxvalue <i>string_alignCharOff</i>
305      * @netui:attribute required="false" rtexprvalue="true" description="The horizontal alignment character offset of the HTML tfoot tag"
306      */

307     public void setCharoff(String JavaDoc alignCharOff) {
308         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAROFF, alignCharOff);
309     }
310
311     /**
312      * Sets the value of the vertical alignment attribute.
313      *
314      * @param align
315      * @jsptagref.attributedescription The vertical alignment.
316      * @jsptagref.attributesyntaxvalue <i>string_align</i>
317      * @netui:attribute required="false" rtexprvalue="true" description="The cell's vertical alignment"
318      */

319     public void setValign(String JavaDoc align) {
320         /* todo: should this enforce top|middle|bottom|baseline as in the spec? */
321         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.VALIGN, align);
322     }
323
324     /**
325      * Sets the value of the language attribute.
326      *
327      * @param lang
328      * @jsptagref.attributedescription The language.
329      * @jsptagref.attributesyntaxvalue <i>string_lang</i>
330      * @netui:attribute required="false" rtexprvalue="true" description="The cell's language"
331      */

332     public void setLang(String JavaDoc lang) {
333         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang);
334     }
335
336     /**
337      * Sets the value of the text direction attribute.
338      *
339      * @param dir
340      * @jsptagref.attributedescription The text direction attribute.
341      * @jsptagref.attributesyntaxvalue <i>string_dir</i>
342      * @netui:attribute required="false" rtexprvalue="true" description="The cell's text direction"
343      */

344     public void setDir(String JavaDoc dir) {
345         _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
346     }
347
348     /**
349      * Set a boolean that enables / disables rendering HTML table rows by this tag. If the
350      * value is enabled, an HTML &lt;tr&gt; will be rendered when this tag renders its body. If
351      * the value is disabled, no &lt;tr&gt; tags will be rendered and the page author is responsible
352      * for maintaining the integrity of the HTML table.
353      * @jsptagref.attributedescription
354      * Set a boolean that enables / disables rendering HTML table rows by this tag. If the
355      * value is enabled, an HTML &lt;tr&gt; will be rendered when this tag renders its body. If
356      * the value is disabled, no &lt;tr&gt; tags will be rendered and the page author is responsible
357      * for maintaining the integrity of the HTML table.
358      * @jsptagref.attributesyntaxvalue <i>boolean_renderRow</i>
359      * @netui:attribute required="false" rtexprvalue="true"
360      * description="Boolean to enable / disable rendering HTML table row tags"
361      */

362     public void setRenderRow(boolean renderRow) {
363         _renderRow = renderRow;
364     }
365
366     /**
367      * Set the name of the tagId for the HTML tfoot tag.
368      *
369      * @param tagId the tag id
370      * @jsptagref.attributedescription The tagId of the HTML tfoot tag.
371      * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
372      * @netui:attribute required="false" rtexprvalue="true"
373      * description="String value. Sets the id (or name) attribute of the HTML tfoot tag."
374      */

375     public void setTagId(String JavaDoc tagId)
376         throws JspException JavaDoc {
377         applyTagId(_tfootTag, tagId);
378     }
379
380     /**
381      * Render this tag. This method renders during the data grid's {@link DataGridTagModel#RENDER_STATE_FOOTER}
382      * state in order to add table rows to the end of a data grid's HTML table. If the data grid is rendering
383      * HTML row groups, this tag will output an HTML &lt;tfoot&gt; tag. Then, if this tag is rendering
384      * a table row, it will produce an HTML &lt;tr&gt; tag. Then the content of the body will be rendered. If
385      * table row rendering is disabled, the page author is responsible for rendering the appropriate HTML
386      * table row tags as this tag renders inside of the HTML table opened by the data grid.
387      * @throws IOException
388      * @throws JspException when the {@link DataGridTagModel} can not be found in the {@link JspContext}
389      */

390     public void doTag()
391             throws IOException JavaDoc, JspException JavaDoc {
392
393         JspContext JavaDoc jspContext = getJspContext();
394
395         DataGridTagModel dgm = DataGridUtil.getDataGridTagModel(jspContext);
396         if(dgm == null)
397             throw new JspException JavaDoc(Bundle.getErrorString("DataGridTags_MissingDataGridModel"));
398
399         if(dgm.getRenderState() == DataGridTagModel.RENDER_STATE_FOOTER) {
400             JspFragment JavaDoc fragment = getJspBody();
401             if(fragment != null) {
402
403                 StringWriter JavaDoc sw = new StringWriter JavaDoc();
404
405                 TableRenderer tableRenderer = dgm.getTableRenderer();
406                 assert tableRenderer != null;
407
408                 StyleModel styleModel = dgm.getStyleModel();
409                 assert styleModel != null;
410
411                 AbstractRenderAppender appender = new WriteRenderAppender(jspContext);
412
413                 if(dgm.isRenderRowGroups()) {
414                     if(_tfootTag.styleClass == null)
415                         _tfootTag.styleClass = styleModel.getTableFootClass();
416                     tableRenderer.openTableFoot(_tfootTag, appender);
417                 }
418
419                 TrTag.State trState = null;
420                 if(_renderRow) {
421                     trState = new TrTag.State();
422                     trState.styleClass = styleModel.getFooterRowClass();
423                     tableRenderer.openFooterRow(trState, appender);
424                 }
425
426                 fragment.invoke(sw);
427                 appender.append(sw.toString());
428
429                 if(_renderRow) {
430                     assert trState != null;
431                     tableRenderer.closeFooterRow(appender);
432                 }
433
434                 if(dgm.isRenderRowGroups()) {
435                     tableRenderer.closeTableFoot(appender);
436
437                     String JavaDoc tfootScript = null;
438                     if(_tfootTag.id != null) {
439                         HttpServletRequest JavaDoc request = JspUtil.getRequest(getJspContext());
440                         tfootScript = renderNameAndId(request, _tfootTag, null);
441                     }
442
443                     if(tfootScript != null)
444                         appender.append(tfootScript);
445                 }
446             }
447         }
448     }
449 }
450
Popular Tags