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.JspContext;
022:
023: import org.apache.beehive.netui.tags.AbstractSimpleTag;
024: import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfig;
025: import org.apache.beehive.netui.databinding.datagrid.api.DataGridStateFactory;
026: import org.apache.beehive.netui.databinding.datagrid.api.DataGridState;
027:
028: /**
029: * <p>
030: * Utility data grid tag that allows the page author to gain access to the {@link DataGridState} object
031: * outside of the body of a <netui-data:dataGrid> tag. When building UI for sorting, filtering, or paging,
032: * this UI does not need to exist inside of the HTML table rendered by the data grid tags. In order to render
033: * UI for sorting, filtering, and paging, it is often necessary to gain access to the state exposed to a data
034: * grid via the {@link DataGridState} object. For example:
035: * <pre>
036: * <netui-data:getDataGridState gridName="employees" var="employeeGridState"/>
037: * <c:if test="${pageScope.employeeGridState.sortModel.sorts} != null}">
038: * ... render UI when sorts are present ...
039: * </c:if>
040: * </pre>
041: * this will expose the "employees" data grid's list of
042: * {@link org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel#getSorts()} to the JSP for access by
043: * the JSP EL.
044: * </p>
045: * @jsptagref.tagdescription
046: * <p>
047: * Utility data grid tag that allows the page author to gain access to the {@link DataGridState} object
048: * outside of the body of a <netui-data:dataGrid> tag. When building UI for sorting, filtering, or paging,
049: * this UI does not need to exist inside of the HTML table rendered by the data grid tags. In order to render
050: * UI for sorting, filtering, and paging, it is often necessary to gain access to the state exposed to a data
051: * grid via the {@link DataGridState} object. For example:
052: * <pre>
053: * <netui-data:getDataGridState gridName="employees" var="employeeGridState"/>
054: * <c:if test="${pageScope.employeeGridState.sortModel.sorts} != null}">
055: * ... render UI when sorts are present ...
056: * </c:if>
057: * </pre>
058: * this will expose the "employees" data grid's list of
059: * {@link org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel#getSorts()} to the JSP for access by
060: * the JSP EL.
061: * </p>
062: *
063: * @netui:tag name="getDataGridState" body-content="scriptless"
064: * description="Get a DataGridState object and add it to the PageContext under a given variable name"
065: */
066: public class GetDataGridState extends AbstractSimpleTag {
067:
068: private String _var = null;
069: private String _name = null;
070: private DataGridConfig _config = null;
071:
072: /**
073: * The name of this tag; this value is used for error reporting.
074: * @return the String name of this tag
075: */
076: public final String getTagName() {
077: return "GetDataGridState";
078: }
079:
080: /**
081: * Set the data grid name whose {@link DataGridState} should be placed in the {@link JspContext}.
082: *
083: * @param name the name of the data grid
084: * @jsptagref.attributedescription
085: * Set the data grid name whose {@link DataGridState} should be placed in the {@link JspContext}.
086: * @jsptagref.attributesyntaxvalue <i>string_gridName</i>
087: * @netui:attribute name="name" required="true"
088: * description="Set the name of the data grid whose DataGridState to lookup."
089: */
090: public void setGridName(String name) {
091: _name = name;
092: }
093:
094: /**
095: * Set the name used to store the {@link DataGridState} object as a {@link JspContext} attribute.
096: * @param var the name used to store the {@link DataGridState}
097: * @jsptagref.attributedescription
098: * Set the name used to store the {@link DataGridState} object as a {@link JspContext} attribute.
099: * @jsptagref.attributesyntaxvalue <i>string_var</i>
100: * @netui:attribute name="var" required="true"
101: */
102: public void setVar(String var) {
103: _var = var;
104: }
105:
106: /**
107: * Set a {@link DataGridConfig} instance used to create a {@link DataGridState} object. This attribute is
108: * optional; when unset, the default {@link DataGridConfig} is used.
109: * @param config the {@link DataGridConfig} used to create the {@link DataGridState}
110: * @jsptagref.attributedescription
111: * Set a {@link DataGridConfig} instance used to create a {@link DataGridState} object. This attribute is
112: * optional; when unset, the default {@link DataGridConfig} is used.
113: * @jsptagref.attributesyntaxvalue <i>string_var</i>
114: * @netui:attribute name="name" required="false"
115: * description="Set an optional DataGridConfig instance used to create the DataGridState object."
116: */
117: public void setDataGridConfig(DataGridConfig config) {
118: _config = config;
119: }
120:
121: /**
122: * Using a {@link DataGridConfig} object, access the {@link DataGridState} and place
123: * it in the {@link JspContext} under the attribute key set via {@link #setVar(String)}
124: */
125: public void doTag() {
126: JspContext jspContext = getJspContext();
127: DataGridStateFactory factory = DataGridStateFactory
128: .getInstance(jspContext);
129: assert factory != null;
130:
131: DataGridState state = null;
132: if (_config != null)
133: state = factory.getDataGridState(_name, _config);
134: else
135: state = factory.getDataGridState(_name);
136:
137: jspContext.setAttribute(_var, state);
138: }
139: }
|