KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspContext JavaDoc;
21
22 import org.apache.beehive.netui.tags.AbstractSimpleTag;
23 import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfig;
24 import org.apache.beehive.netui.databinding.datagrid.api.DataGridStateFactory;
25 import org.apache.beehive.netui.databinding.datagrid.api.DataGridState;
26
27 /**
28  * <p>
29  * Utility data grid tag that allows the page author to gain access to the {@link DataGridState} object
30  * outside of the body of a &lt;netui-data:dataGrid&gt; tag. When building UI for sorting, filtering, or paging,
31  * this UI does not need to exist inside of the HTML table rendered by the data grid tags. In order to render
32  * UI for sorting, filtering, and paging, it is often necessary to gain access to the state exposed to a data
33  * grid via the {@link DataGridState} object. For example:
34  * <pre>
35  * &lt;netui-data:getDataGridState gridName="employees" var="employeeGridState"/>
36  * &lt;c:if test="${pageScope.employeeGridState.sortModel.sorts} != null}">
37  * ... render UI when sorts are present ...
38  * &lt;/c:if>
39  * </pre>
40  * this will expose the "employees" data grid's list of
41  * {@link org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel#getSorts()} to the JSP for access by
42  * the JSP EL.
43  * </p>
44  * @jsptagref.tagdescription
45  * <p>
46  * Utility data grid tag that allows the page author to gain access to the {@link DataGridState} object
47  * outside of the body of a &lt;netui-data:dataGrid&gt; tag. When building UI for sorting, filtering, or paging,
48  * this UI does not need to exist inside of the HTML table rendered by the data grid tags. In order to render
49  * UI for sorting, filtering, and paging, it is often necessary to gain access to the state exposed to a data
50  * grid via the {@link DataGridState} object. For example:
51  * <pre>
52  * &lt;netui-data:getDataGridState gridName="employees" var="employeeGridState"/>
53  * &lt;c:if test="${pageScope.employeeGridState.sortModel.sorts} != null}">
54  * ... render UI when sorts are present ...
55  * &lt;/c:if>
56  * </pre>
57  * this will expose the "employees" data grid's list of
58  * {@link org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel#getSorts()} to the JSP for access by
59  * the JSP EL.
60  * </p>
61  *
62  * @netui:tag name="getDataGridState" body-content="scriptless"
63  * description="Get a DataGridState object and add it to the PageContext under a given variable name"
64  */

65 public class GetDataGridState
66     extends AbstractSimpleTag {
67
68     private String JavaDoc _var = null;
69     private String JavaDoc _name = null;
70     private DataGridConfig _config = null;
71
72     /**
73      * The name of this tag; this value is used for error reporting.
74      * @return the String name of this tag
75      */

76     public final String JavaDoc getTagName() {
77         return "GetDataGridState";
78     }
79
80     /**
81      * Set the data grid name whose {@link DataGridState} should be placed in the {@link JspContext}.
82      *
83      * @param name the name of the data grid
84      * @jsptagref.attributedescription
85      * Set the data grid name whose {@link DataGridState} should be placed in the {@link JspContext}.
86      * @jsptagref.attributesyntaxvalue <i>string_gridName</i>
87      * @netui:attribute name="name" required="true"
88      * description="Set the name of the data grid whose DataGridState to lookup."
89      */

90     public void setGridName(String JavaDoc name) {
91         _name = name;
92     }
93
94     /**
95      * Set the name used to store the {@link DataGridState} object as a {@link JspContext} attribute.
96      * @param var the name used to store the {@link DataGridState}
97      * @jsptagref.attributedescription
98      * Set the name used to store the {@link DataGridState} object as a {@link JspContext} attribute.
99      * @jsptagref.attributesyntaxvalue <i>string_var</i>
100      * @netui:attribute name="var" required="true"
101      */

102     public void setVar(String JavaDoc 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 JavaDoc jspContext = getJspContext();
127         DataGridStateFactory factory = DataGridStateFactory.getInstance(jspContext);
128         assert factory != null;
129
130         DataGridState state = null;
131         if(_config != null)
132             state = factory.getDataGridState(_name, _config);
133         else
134             state = factory.getDataGridState(_name);
135
136         jspContext.setAttribute(_var, state);
137     }
138 }
139
Popular Tags