001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.databinding.datagrid;
020:
021: import java.io.IOException;
022: import java.io.StringWriter;
023: import javax.servlet.jsp.tagext.JspFragment;
024: import javax.servlet.jsp.JspException;
025: import javax.servlet.jsp.JspContext;
026: import javax.servlet.http.HttpServletRequest;
027:
028: import org.apache.beehive.netui.tags.IHtmlEvents;
029: import org.apache.beehive.netui.tags.IHtmlI18n;
030: import org.apache.beehive.netui.tags.html.HtmlConstants;
031: import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
032: import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
033: import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
034: import org.apache.beehive.netui.tags.rendering.TFootTag;
035: import org.apache.beehive.netui.tags.rendering.TrTag;
036: import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
037: import org.apache.beehive.netui.databinding.datagrid.api.rendering.StyleModel;
038: import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer;
039: import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
040: import org.apache.beehive.netui.util.Bundle;
041:
042: /**
043: * <p>
044: * The Footer tag is used to render a table row after the data grid has rendered the
045: * header and rows regions demarcated by the {@link Header} and {@link Rows} tags respectively.
046: * The footer tag can also optionally render a <tfoot> HTML tag if the data grid is rendering
047: * HTML table row groups. To enable this functionality, set the {@link DataGrid#setRenderRowGroups(boolean)}
048: * attribute. The location of the footer tag inside of a data grid does not affect when its content renders.
049: * </p>
050: * <p>
051: * The attribute setters for the footer tag are used to add HTML attributes to the ≶tfoot> HTML
052: * tag. When row group rendering is disabled, attributes set here do not render.
053: * </p>
054: * <p>
055: * Because this tag renders inside of an HTML table, it by default renders an HTML
056: * <tr> tag to represent a table row. Table row tag rendering can be disabled using the {@link #setRenderRow(boolean)}
057: * attribute. When this is disabled, the page author is responsible for maintaining the integrity of the
058: * HTML table by writing <tr> tags manually or by using the {@link Row} tag. When this tag is rendering
059: * it does not produce table cells; the contents of the table row in the footer is entirely left to the
060: * page author. With row rendering disabled, it is also possible to add multiple table rows to the
061: * end of a data grid.
062: * </p>
063: * <p>
064: * The set of JSP implicit objects available to the body include:
065: * <ul>
066: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
067: * for the cell's containing data grid.</li>
068: * </ul>
069: * </p>
070: * @jsptagref.tagdescription
071: * <p>
072: * The Footer tag is used to render a table row after the data grid has rendered the
073: * header and rows regions demarcated by the {@link Header} and {@link Rows} tags respectively.
074: * The footer tag can also optionally render a <tfoot> HTML tag if the data grid is rendering
075: * HTML table row groups. To enable this functionality, set the {@link DataGrid#setRenderRowGroups(boolean)}
076: * attribute. The location of the footer tag inside of a data grid does not affect when its content renders.
077: * </p>
078: * <p>
079: * The attribute setters for the footer tag are used to add HTML attributes to the ≶tfoot> HTML
080: * tag. When row group rendering is disabled, attributes set here do not render.
081: * </p>
082: * <p>
083: * Because this tag renders inside of an HTML table, it by default renders an HTML
084: * <tr> tag to represent a table row. Table row tag rendering can be disabled using the {@link #setRenderRow(boolean)}
085: * attribute. When this is disabled, the page author is responsible for maintaining the integrity of the
086: * HTML table by writing <tr> tags manually or by using the {@link Row} tag. When this tag is rendering
087: * it does not produce table cells; the contents of the table row in the footer is entirely left to the
088: * page author. With row rendering disabled, it is also possible to add multiple table rows to the
089: * end of a data grid.
090: * </p>
091: * <p>
092: * The set of JSP implicit objects available to the body include:
093: * <ul>
094: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
095: * for the cell's containing data grid.</li>
096: * </ul>
097: * </p>
098: * @netui:tag name="footer" body-content="scriptless" description="Renders a footer into a NetUI data grid"
099: */
100: public class Footer extends AbstractDataGridHtmlTag implements
101: 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 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 onClick) {
123: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
124: HtmlConstants.ONCLICK, onClick);
125: }
126:
127: /**
128: * Sets the onDblClick JavaScript event for the HTML tfoot.
129: *
130: * @param onDblClick the onDblClick event.
131: * @jsptagref.attributedescription The onDblClick JavaScript event for the HTML tfoot.
132: * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
133: * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event for the HTML tfoot."
134: */
135: public void setOnDblClick(String onDblClick) {
136: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
137: HtmlConstants.ONDBLCLICK, onDblClick);
138: }
139:
140: /**
141: * Sets the onKeyDown JavaScript event for the HTML tfoot.
142: *
143: * @param onKeyDown the onKeyDown event.
144: * @jsptagref.attributedescription The onKeyDown JavaScript event for the HTML tfoot.
145: * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
146: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event for the HTML tfoot."
147: */
148: public void setOnKeyDown(String onKeyDown) {
149: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
150: HtmlConstants.ONKEYDOWN, onKeyDown);
151: }
152:
153: /**
154: * Sets the onKeyUp JavaScript event for the HTML tfoot.
155: *
156: * @param onKeyUp the onKeyUp event.
157: * @jsptagref.attributedescription The onKeyUp JavaScript event for the HTML tfoot.
158: * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
159: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event for the HTML tfoot."
160: */
161: public void setOnKeyUp(String onKeyUp) {
162: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
163: HtmlConstants.ONKEYUP, onKeyUp);
164: }
165:
166: /**
167: * Sets the onKeyPress JavaScript event.
168: *
169: * @param onKeyPress the onKeyPress event.
170: * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML tfoot.
171: * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
172: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event for the HTML tfoot."
173: */
174: public void setOnKeyPress(String onKeyPress) {
175: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
176: HtmlConstants.ONKEYPRESS, onKeyPress);
177: }
178:
179: /**
180: * Sets the onMouseDown JavaScript event for the HTML tfoot.
181: *
182: * @param onMouseDown the onMouseDown event.
183: * @jsptagref.attributedescription The onMouseDown JavaScript event for the HTML tfoot.
184: * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
185: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event for the HTML tfoot."
186: */
187: public void setOnMouseDown(String onMouseDown) {
188: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
189: HtmlConstants.ONMOUSEDOWN, onMouseDown);
190: }
191:
192: /**
193: * Sets the onMouseUp JavaScript event for the HTML tfoot.
194: *
195: * @param onMouseUp the onMouseUp event.
196: * @jsptagref.attributedescription The onMouseUp JavaScript event for the HTML tfoot.
197: * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
198: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event for the HTML tfoot."
199: */
200: public void setOnMouseUp(String onMouseUp) {
201: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
202: HtmlConstants.ONMOUSEUP, onMouseUp);
203: }
204:
205: /**
206: * Sets the onMouseMove JavaScript event for the HTML tfoot.
207: *
208: * @param onMouseMove the onMouseMove event.
209: * @jsptagref.attributedescription The onMouseMove JavaScript event for the HTML tfoot.
210: * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
211: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event for the HTML tfoot."
212: */
213: public void setOnMouseMove(String onMouseMove) {
214: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
215: HtmlConstants.ONMOUSEMOVE, onMouseMove);
216: }
217:
218: /**
219: * Sets the onMouseOut JavaScript event for the HTML tfoot.
220: *
221: * @param onMouseOut the onMouseOut event.
222: * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML tfoot.
223: * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
224: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event for the HTML tfoot."
225: */
226: public void setOnMouseOut(String onMouseOut) {
227: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
228: HtmlConstants.ONMOUSEOUT, onMouseOut);
229: }
230:
231: /**
232: * Sets the onMouseOver JavaScript event for the HTML tfoot.
233: *
234: * @param onMouseOver the onMouseOver event.
235: * @jsptagref.attributedescription The onMouseOver JavaScript event for the HTML tfoot.
236: * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
237: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event for the HTML tfoot."
238: */
239: public void setOnMouseOver(String onMouseOver) {
240: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
241: HtmlConstants.ONMOUSEOVER, onMouseOver);
242: }
243:
244: /**
245: * Sets the style of the HTML tfoot tag.
246: *
247: * @param style the style
248: * @jsptagref.attributedescription The style for the HTML tfoot tag.
249: * @jsptagref.attributesyntaxvalue <i>string_style</i>
250: * @netui:attribute required="false" rtexprvalue="true" description="The style for the HTML tfoot tag."
251: */
252: public void setStyle(String style) {
253: if ("".equals(style))
254: return;
255:
256: _tfootTag.style = style;
257: }
258:
259: /**
260: * Sets the style class of the rendered html tag.
261: *
262: * @param styleClass the style class
263: * @jsptagref.attributedescription The style class of the HTML tfoot tag.
264: * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
265: * @netui:attribute required="false" rtexprvalue="true" description="The style class of the HTML tfoot tag."
266: */
267: public void setStyleClass(String styleClass) {
268: if ("".equals(styleClass))
269: return;
270:
271: _tfootTag.styleClass = styleClass;
272: }
273:
274: /**
275: * Sets the value of the title attribute of the HTML tfoot tag.
276: *
277: * @param title
278: * @jsptagref.attributedescription The title of the HTML tfoot tag.
279: * @jsptagref.attributesyntaxvalue <i>string_title</i>
280: * @netui:attribute required="false" rtexprvalue="true" description="The title of the HTML tfoot tag."
281: */
282: public void setTitle(String title) {
283: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
284: HtmlConstants.TITLE, title);
285: }
286:
287: /**
288: * Sets the value of the horizontal align attribute of the HTML tfoot tag.
289: *
290: * @param align the alignment
291: * @jsptagref.attributedescription The horizontal alignment of the HTML tfoot tag.
292: * @jsptagref.attributesyntaxvalue <i>string_align</i>
293: * @netui:attribute required="false" rtexprvalue="true" description="The cell's horizontal alignment of the HTML tfoot tag"
294: */
295: public void setAlign(String align) {
296: /* todo: should this enforce left|center|right|justify|char as in the spec? */
297: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
298: HtmlConstants.ALIGN, align);
299: }
300:
301: /**
302: * Sets the value of the horizontal alignment character attribute of the HTML tfoot tag.
303: *
304: * @param alignChar the alignment character
305: * @jsptagref.attributedescription The horizontal alignment character of the HTML tfoot tag
306: * @jsptagref.attributesyntaxvalue <i>string_alignChar</i>
307: * @netui:attribute required="false" rtexprvalue="true" description="The cell's horizontal alignment character of the HTML tfoot tag"
308: */
309: public void setChar(String alignChar) {
310: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
311: HtmlConstants.CHAR, alignChar);
312: }
313:
314: /**
315: * Sets the value of the horizontal alignment character offset attribute of the HTML tfoot tag
316: *
317: * @param alignCharOff the character alignment offset
318: * @jsptagref.attributedescription The horizontal alignment character offset of the HTML tfoot tag.
319: * @jsptagref.attributesyntaxvalue <i>string_alignCharOff</i>
320: * @netui:attribute required="false" rtexprvalue="true" description="The horizontal alignment character offset of the HTML tfoot tag"
321: */
322: public void setCharoff(String alignCharOff) {
323: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
324: HtmlConstants.CHAROFF, alignCharOff);
325: }
326:
327: /**
328: * Sets the value of the vertical alignment attribute.
329: *
330: * @param align
331: * @jsptagref.attributedescription The vertical alignment.
332: * @jsptagref.attributesyntaxvalue <i>string_align</i>
333: * @netui:attribute required="false" rtexprvalue="true" description="The cell's vertical alignment"
334: */
335: public void setValign(String align) {
336: /* todo: should this enforce top|middle|bottom|baseline as in the spec? */
337: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
338: HtmlConstants.VALIGN, align);
339: }
340:
341: /**
342: * Sets the value of the language attribute.
343: *
344: * @param lang
345: * @jsptagref.attributedescription The language.
346: * @jsptagref.attributesyntaxvalue <i>string_lang</i>
347: * @netui:attribute required="false" rtexprvalue="true" description="The cell's language"
348: */
349: public void setLang(String lang) {
350: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
351: HtmlConstants.LANG, lang);
352: }
353:
354: /**
355: * Sets the value of the text direction attribute.
356: *
357: * @param dir
358: * @jsptagref.attributedescription The text direction attribute.
359: * @jsptagref.attributesyntaxvalue <i>string_dir</i>
360: * @netui:attribute required="false" rtexprvalue="true" description="The cell's text direction"
361: */
362: public void setDir(String dir) {
363: _tfootTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
364: HtmlConstants.DIR, dir);
365: }
366:
367: /**
368: * Set a boolean that enables / disables rendering HTML table rows by this tag. If the
369: * value is enabled, an HTML <tr> will be rendered when this tag renders its body. If
370: * the value is disabled, no <tr> tags will be rendered and the page author is responsible
371: * for maintaining the integrity of the HTML table.
372: * @jsptagref.attributedescription
373: * Set a boolean that enables / disables rendering HTML table rows by this tag. If the
374: * value is enabled, an HTML <tr> will be rendered when this tag renders its body. If
375: * the value is disabled, no <tr> tags will be rendered and the page author is responsible
376: * for maintaining the integrity of the HTML table.
377: * @jsptagref.attributesyntaxvalue <i>boolean_renderRow</i>
378: * @netui:attribute required="false" rtexprvalue="true"
379: * description="Boolean to enable / disable rendering HTML table row tags"
380: */
381: public void setRenderRow(boolean renderRow) {
382: _renderRow = renderRow;
383: }
384:
385: /**
386: * Set the name of the tagId for the HTML tfoot tag.
387: *
388: * @param tagId the tag id
389: * @jsptagref.attributedescription The tagId of the HTML tfoot tag.
390: * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
391: * @netui:attribute required="false" rtexprvalue="true"
392: * description="String value. Sets the id (or name) attribute of the HTML tfoot tag."
393: */
394: public void setTagId(String tagId) throws JspException {
395: applyTagId(_tfootTag, tagId);
396: }
397:
398: /**
399: * Render this tag. This method renders during the data grid's {@link DataGridTagModel#RENDER_STATE_FOOTER}
400: * state in order to add table rows to the end of a data grid's HTML table. If the data grid is rendering
401: * HTML row groups, this tag will output an HTML <tfoot> tag. Then, if this tag is rendering
402: * a table row, it will produce an HTML <tr> tag. Then the content of the body will be rendered. If
403: * table row rendering is disabled, the page author is responsible for rendering the appropriate HTML
404: * table row tags as this tag renders inside of the HTML table opened by the data grid.
405: * @throws IOException
406: * @throws JspException when the {@link DataGridTagModel} can not be found in the {@link JspContext}
407: */
408: public void doTag() throws IOException, JspException {
409:
410: JspContext jspContext = getJspContext();
411:
412: DataGridTagModel dgm = DataGridUtil
413: .getDataGridTagModel(jspContext);
414: if (dgm == null)
415: throw new JspException(
416: Bundle
417: .getErrorString("DataGridTags_MissingDataGridModel"));
418:
419: if (dgm.getRenderState() == DataGridTagModel.RENDER_STATE_FOOTER) {
420: JspFragment fragment = getJspBody();
421: if (fragment != null) {
422:
423: StringWriter sw = new StringWriter();
424:
425: TableRenderer tableRenderer = dgm.getTableRenderer();
426: assert tableRenderer != null;
427:
428: StyleModel styleModel = dgm.getStyleModel();
429: assert styleModel != null;
430:
431: AbstractRenderAppender appender = new WriteRenderAppender(
432: jspContext);
433:
434: if (dgm.isRenderRowGroups()) {
435: if (_tfootTag.styleClass == null)
436: _tfootTag.styleClass = styleModel
437: .getTableFootClass();
438: tableRenderer.openTableFoot(_tfootTag, appender);
439: }
440:
441: TrTag.State trState = null;
442: if (_renderRow) {
443: trState = new TrTag.State();
444: trState.styleClass = styleModel.getFooterRowClass();
445: tableRenderer.openFooterRow(trState, appender);
446: }
447:
448: fragment.invoke(sw);
449: appender.append(sw.toString());
450:
451: if (_renderRow) {
452: assert trState != null;
453: tableRenderer.closeFooterRow(appender);
454: }
455:
456: if (dgm.isRenderRowGroups()) {
457: tableRenderer.closeTableFoot(appender);
458:
459: String tfootScript = null;
460: if (_tfootTag.id != null) {
461: HttpServletRequest request = JspUtil
462: .getRequest(getJspContext());
463: tfootScript = renderNameAndId(request,
464: _tfootTag, null);
465: }
466:
467: if (tfootScript != null)
468: appender.append(tfootScript);
469: }
470: }
471: }
472: }
473: }
|