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