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 javax.servlet.jsp.JspException;
022: import javax.servlet.http.HttpServletRequest;
023:
024: import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
025: import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.SpanCellModel;
026: import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.SpanCellDecorator;
027: import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
028: import org.apache.beehive.netui.tags.html.HtmlConstants;
029: import org.apache.beehive.netui.tags.html.IFormattable;
030: import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
031: import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
032: import org.apache.beehive.netui.tags.rendering.SpanTag;
033: import org.apache.beehive.netui.tags.IHtmlCore;
034: import org.apache.beehive.netui.tags.IHtmlI18n;
035: import org.apache.beehive.netui.tags.IHtmlEvents;
036:
037: /**
038: * <p>
039: * Data grid cell that renders an HTML <span> tag containing the tag's <code>value</code> attribute. The
040: * span cell is rendered inside of an HTML table <td>. The span cell supports various nested tags including
041: * those that provide formatting via the NetUI {@link IFormattable} interface and those that augment the
042: * available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface.
043: * </p>
044: * <p>
045: * The set of JSP implicit objects available to the body include:
046: * <ul>
047: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
048: * for the cell's containing data grid.</li>
049: * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
050: * that exposes the current data item and the current item's index</li>
051: * </ul>
052: * </p>
053: *
054: * @jsptagref.tagdescription
055: * <p>
056: * Data grid cell that renders an HTML <span> tag containing the tag's <code>value</code> attribute. The
057: * span cell is rendered inside of an HTML table <td>. The span cell supports various nested tags including
058: * those that provide formatting via the NetUI {@link IFormattable} interface and those that augment the
059: * available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface.
060: * </p>
061: * <p>
062: * The set of JSP implicit objects available to the body include:
063: * <ul>
064: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
065: * for the cell's containing data grid.</li>
066: * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
067: * that exposes the current data item and the current item's index</li>
068: * </ul>
069: * </p>
070: *
071: * @netui:tag name="spanCell" body-content="scriptless"
072: * description="Data grid cell that renders its value attribute into an HTML <span>"
073: */
074: public class SpanCell extends AbstractHtmlTableCell implements
075: IFormattable, IHtmlCore, IHtmlEvents, IHtmlI18n {
076:
077: private static final SpanCellDecorator DECORATOR = new SpanCellDecorator();
078: private static final String SPAN_FACET_NAME = "span";
079:
080: private SpanCellModel _spanCellModel = new SpanCellModel();
081: private SpanTag.State _spanState = _spanCellModel.getSpanState();
082:
083: /**
084: * The name of this tag; this value is used for error reporting.
085: * @return the String name of this tag
086: */
087: public String getTagName() {
088: return "SpanCell";
089: }
090:
091: /**
092: * Sets the onClick JavaScript event for the HTML span.
093: *
094: * @param onClick the onClick event for the HTML span.
095: * @jsptagref.attributedescription The onClick JavaScript event for the HTML span.
096: * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
097: * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event."
098: */
099: public void setOnClick(String onClick) {
100: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
101: HtmlConstants.ONCLICK, onClick);
102: }
103:
104: /**
105: * Sets the onDblClick JavaScript event for the HTML span.
106: *
107: * @param onDblClick the onDblClick event for the HTML span.
108: * @jsptagref.attributedescription The onDblClick JavaScript event for the HTML span.
109: * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
110: * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event for the HTML span."
111: */
112: public void setOnDblClick(String onDblClick) {
113: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
114: HtmlConstants.ONDBLCLICK, onDblClick);
115: }
116:
117: /**
118: * Sets the onKeyDown JavaScript event for the HTML span.
119: *
120: * @param onKeyDown the onKeyDown event for the HTML span.
121: * @jsptagref.attributedescription The onKeyDown JavaScript event for the HTML span.
122: * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
123: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event for the HTML span."
124: */
125: public void setOnKeyDown(String onKeyDown) {
126: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
127: HtmlConstants.ONKEYDOWN, onKeyDown);
128: }
129:
130: /**
131: * Sets the onKeyUp JavaScript event for the HTML span.
132: *
133: * @param onKeyUp the onKeyUp event.
134: * @jsptagref.attributedescription The onKeyUp JavaScript event for the HTML span.
135: * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
136: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event for the HTML span."
137: */
138: public void setOnKeyUp(String onKeyUp) {
139: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
140: HtmlConstants.ONKEYUP, onKeyUp);
141: }
142:
143: /**
144: * Sets the onKeyPress JavaScript event for the HTML span.
145: *
146: * @param onKeyPress the onKeyPress event.
147: * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML span.
148: * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
149: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event for the HTML span."
150: */
151: public void setOnKeyPress(String onKeyPress) {
152: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
153: HtmlConstants.ONKEYPRESS, onKeyPress);
154: }
155:
156: /**
157: * Sets the onMouseDown JavaScript event for the HTML span.
158: *
159: * @param onMouseDown the onMouseDown event.
160: * @jsptagref.attributedescription The onMouseDown JavaScript event for the HTML span.
161: * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
162: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event for the HTML span."
163: */
164: public void setOnMouseDown(String onMouseDown) {
165: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
166: HtmlConstants.ONMOUSEDOWN, onMouseDown);
167: }
168:
169: /**
170: * Sets the onMouseUp JavaScript event for the HTML span.
171: *
172: * @param onMouseUp the onMouseUp event.
173: * @jsptagref.attributedescription The onMouseUp JavaScript event for the HTML span.
174: * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
175: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event for the HTML span."
176: */
177: public void setOnMouseUp(String onMouseUp) {
178: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
179: HtmlConstants.ONMOUSEUP, onMouseUp);
180: }
181:
182: /**
183: * Sets the onMouseMove JavaScript event for the HTML span.
184: *
185: * @param onMouseMove the onMouseMove event.
186: * @jsptagref.attributedescription The onMouseMove JavaScript event for the HTML span.
187: * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
188: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event for the HTML span."
189: */
190: public void setOnMouseMove(String onMouseMove) {
191: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
192: HtmlConstants.ONMOUSEMOVE, onMouseMove);
193: }
194:
195: /**
196: * Sets the onMouseOut JavaScript event for the HTML span.
197: *
198: * @param onMouseOut the onMouseOut event.
199: * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML span.
200: * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
201: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event for the HTML span."
202: */
203: public void setOnMouseOut(String onMouseOut) {
204: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
205: HtmlConstants.ONMOUSEOUT, onMouseOut);
206: }
207:
208: /**
209: * Sets the onMouseOver JavaScript event for the HTML span.
210: *
211: * @param onMouseOver the onMouseOver event.
212: * @jsptagref.attributedescription The onMouseOver JavaScript event for the HTML span.
213: * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
214: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event for the HTML span."
215: */
216: public void setOnMouseOver(String onMouseOver) {
217: _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
218: HtmlConstants.ONMOUSEOVER, onMouseOver);
219: }
220:
221: /**
222: * Sets the style for the HTML span.
223: *
224: * @param style the html style.
225: * @jsptagref.attributedescription The style for the HTML span
226: * @jsptagref.attributesyntaxvalue <i>string_style</i>
227: * @netui:attribute required="false" rtexprvalue="true" description="The style for the HTML span"
228: */
229: public void setStyle(String style) {
230: if ("".equals(style))
231: return;
232:
233: _spanState.style = style;
234: }
235:
236: /**
237: * Sets the style class for the HTML span.
238: *
239: * @param styleClass the html style class.
240: * @jsptagref.attributedescription The style class for the HTML span
241: * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
242: * @netui:attribute required="false" rtexprvalue="true" description="The style class for the HTML span."
243: */
244: public void setStyleClass(String styleClass) {
245: if ("".equals(styleClass))
246: return;
247:
248: _spanState.styleClass = styleClass;
249: }
250:
251: /**
252: * Sets the value of the title attribute for the HTML span.
253: *
254: * @param title
255: * @jsptagref.attributedescription The title for the HTML span.
256: * @jsptagref.attributesyntaxvalue <i>string_title</i>
257: * @netui:attribute required="false" rtexprvalue="true" description="The title for the HTML span."
258: */
259: public void setTitle(String title) {
260: _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
261: HtmlConstants.TITLE, title);
262: }
263:
264: /**
265: * Sets the lang attribute for the HTML span.
266: * @param lang
267: * @jsptagref.attributedescription The lang for the HTML span.
268: * @jsptagref.attributesyntaxvalue <i>string_lang</i>
269: * @netui:attribute required="false" rtexprvalue="true"
270: * description="The lang for the HTML span"
271: */
272: public void setLang(String lang) {
273: _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
274: HtmlConstants.LANG, lang);
275: }
276:
277: /**
278: * Sets the dir attribute for the HTML span.
279: * @param dir
280: * @jsptagref.attributedescription The dir.
281: * @jsptagref.attributesyntaxvalue <i>string_dir</i>
282: * @netui:attribute required="false" rtexprvalue="true"
283: * description="The dir for the HTML span."
284: */
285: public void setDir(String dir) {
286: _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
287: HtmlConstants.DIR, dir);
288: }
289:
290: /**
291: * <p>
292: * Set the name of the tagId for the HTML span. This value will have the index of the current data item
293: * in the data set appended to the tagId so that the identifiers are unique in the rendered JSP.
294: * </p>
295: * <p>
296: * For example, if a data set contains {"foo", "bar", "baz"} rendered using a spanCell with a tagId
297: * "theTagId", the resulting tagId values will be {"theTagId0", "theTagId1", "theTagId2"}.
298: *
299: * @param tagId the the name of the tagId for the HTML span.
300: * @jsptagref.attributedescription The tagId.
301: * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
302: * @netui:attribute required="false" rtexprvalue="true"
303: * description="String value. Sets the id (or name) attribute of the rendered HTML span."
304: */
305: public void setTagId(String tagId) throws JspException {
306: applyIndexedTagId(_spanState, tagId);
307: }
308:
309: /**
310: * <p>
311: * Set the value rendered inside of the HTML span. This is the visible text that is displayed in the HTML
312: * rendered by this tag.
313: * </p>
314: *
315: * @jsptagref.attributedescription The value of the visible text rendered inside of the HTML span.
316: * @netui:attribute required="true" rtexprvalue="true"
317: */
318: public void setValue(Object value) {
319: _spanCellModel.setValue(value);
320: }
321:
322: /**
323: * <p>
324: * Implementation of {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface. This
325: * allows a page author to add additional attributes to the HTML rendered by this tag. The attribute
326: * facets which can be consumed include:
327: * <ul>
328: * <li><code>span</code> -- attributes set using this facet will be rendered as HTML attributes on the
329: * rendered HTML <span> tag.</li>
330: * </ul>
331: * </p>
332: * <p>
333: * This tag also accepts facets supported by {@link AbstractHtmlTableCell#setAttribute(String, String, String)}
334: * </p>
335: *
336: * @param name the name of the attribute
337: * @param value the value of the attribute
338: * @param facet the facet for the attribute; this value must be match one of the facets supported by the JSP tags
339: * @throws JspException thrown when the given facet String is not recognized as a valid facet name
340: */
341: public void setAttribute(String name, String value, String facet)
342: throws JspException {
343: if (facet == null || facet.equals(SPAN_FACET_NAME))
344: super .addStateAttribute(_spanState, name, value);
345: else
346: super .setAttribute(name, value, facet);
347: }
348:
349: /**
350: * Render the cell's contents. This method implements support for executing the span cell's decorator.
351: * @param appender the {@link AbstractRenderAppender} used to collect the rendered output
352: * @param jspFragmentOutput the String result of having evaluated the span cell's {@link javax.servlet.jsp.tagext.JspFragment}
353: */
354: protected void renderDataCellContents(
355: AbstractRenderAppender appender, String jspFragmentOutput) {
356: /* render any JavaScript needed to support framework features */
357: if (_spanState.id != null) {
358: HttpServletRequest request = JspUtil
359: .getRequest(getJspContext());
360: String script = renderNameAndId(request, _spanState, null);
361: if (script != null)
362: _spanCellModel.setJavascript(script);
363: }
364:
365: DECORATOR.decorate(getJspContext(), appender, _spanCellModel);
366: }
367:
368: /**
369: * Implementation of {@link AbstractHtmlTableCell#internalGetCellModel()} that exposes the
370: * {@link org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.SpanCellModel}
371: * which is storing state for this tag.
372: * @return this tag's span cell model
373: */
374: protected CellModel internalGetCellModel() {
375: return _spanCellModel;
376: }
377: }
|