KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > grid > ColumnTag


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.webapp.taglib.core.grid;
17
18 import com.blandware.atleap.webapp.taglib.core.util.TaglibConstants;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.JspTagException JavaDoc;
24 import javax.servlet.jsp.PageContext JavaDoc;
25 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
26 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 /**
30  * <p>Marks some area as grid's column. <br />
31  * This tag is optional, it can be used to specify one <em>fieldName</em> and
32  * <em>fieldKey</em> for all grid tags which are nested within column.
33  * <br />
34  * This tag is only valid when nested within <em>grid</em> tag.
35  * </p>
36  * <p>
37  * Allowed attributes are:
38  * <ul>
39  * <li>
40  * <b>fieldName</b> - required - name of field that will be assinged to this
41  * column
42  * </li>
43  * <li>
44  * <b>fieldKey</b> - bundle key for localized field name
45  * </li>
46  * <li>
47  * <b>nameVar</b> - name of variable that will store field name. If not
48  * spesified, this will be <code>TaglibConstants.FIELD_NAME_ATTR</code>.
49  * </li>
50  * <li>
51  * <b>keyVar</b> - name of variable that will store field key. If not specified,
52  * this will be <code>TaglibConstants.FIELD_KEY_ATTR</code>.
53  * </li>
54  * </ul>
55  * </p>
56  * <p><a HREF="ColumnTag.java.htm"><i>View Source</i></a></p>
57  *
58  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
59  * @version $Revision: 1.8 $ $Date: 2005/10/12 13:34:56 $
60  * @jsp.tag name="column"
61  * body-content="scriptless"
62  */

63 public class ColumnTag extends SimpleTagSupport JavaDoc {
64
65     protected transient final Log log = LogFactory.getLog(ColumnTag.class);
66
67     /**
68      * Name of field in this column
69      */

70     protected String JavaDoc fieldName = null;
71
72     /**
73      * Bundle key for this field name
74      */

75     protected String JavaDoc fieldKey = null;
76
77     /**
78      * Name of page scope attribute, under which fieldName will be saved
79      */

80     protected String JavaDoc nameVar = TaglibConstants.FIELD_NAME_ATTR;
81
82     /**
83      * Name of page scope attribute under which fieldKey will be saved
84      */

85     protected String JavaDoc keyVar = TaglibConstants.FIELD_KEY_ATTR;
86
87
88     /**
89      * Returns name of field in this column
90      *
91      * @return field name
92      * @jsp.attribute required="true"
93      * rtexprvalue="true"
94      * type="java.lang.String"
95      * description="Name of field in this column"
96      */

97     public String JavaDoc getFieldName() {
98         return fieldName;
99     }
100
101     /**
102      * Sets name of field in this column
103      *
104      * @param fieldName field name
105      */

106     public void setFieldName(String JavaDoc fieldName) {
107         this.fieldName = fieldName;
108     }
109
110     /**
111      * Returns bundle key for field name
112      *
113      * @return bundle key
114      * @jsp.attribute required="false"
115      * rtexprvalue="true"
116      * type="java.lang.String"
117      * description="Bundle key for this field name"
118      */

119     public String JavaDoc getFieldKey() {
120         return fieldKey;
121     }
122
123     /**
124      * Sets bundle key for field name
125      *
126      * @param fieldKey bundle key
127      */

128     public void setFieldKey(String JavaDoc fieldKey) {
129         this.fieldKey = fieldKey;
130     }
131
132     /**
133      * Returns name of page scope attribute, under which field name will be saved
134      *
135      * @return name of page scope attribute, under which field name will be saved
136      * @jsp.attribute required="false"
137      * rtexprvalue="true"
138      * type="java.lang.String"
139      * description="Name of page scope attribute, under which fieldName will be saved"
140      */

141     public String JavaDoc getNameVar() {
142         return nameVar;
143     }
144
145     /**
146      * Sets name of page scope attribute, under which field name will be saved
147      *
148      * @param nameVar name of page scope attribute, under which field name will be saved
149      */

150     public void setNameVar(String JavaDoc nameVar) {
151         this.nameVar = nameVar;
152     }
153
154     /**
155      * Returns name of page scope attribute under which bundle key will be saved
156      *
157      * @return name of page scope attribute under which bundle key will be saved
158      * @jsp.attribute required="false"
159      * rtexprvalue="true"
160      * type="java.lang.String"
161      * description="Name of page scope attribute under which fieldKey will be saved"
162      */

163     public String JavaDoc getKeyVar() {
164         return keyVar;
165     }
166
167     /**
168      * Sets name of page scope attribute under which bundle key will be saved
169      *
170      * @param keyVar name of page scope attribute under which bundle key will be saved
171      */

172     public void setKeyVar(String JavaDoc keyVar) {
173         this.keyVar = keyVar;
174     }
175
176     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
177
178         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
179
180         // This tag is only valid when nested within 'grid' tag, so check this
181
GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class);
182
183         if ( parentGridTag == null ) {
184             JspTagException JavaDoc e = new JspTagException JavaDoc("Parent tag is invalid! This tag is only valid when nested within 'grid' tag");
185             throw e;
186         }
187
188         pageContext.setAttribute(nameVar, fieldName);
189         if ( fieldKey != null && fieldKey.length() > 0 ) {
190             pageContext.setAttribute(keyVar, fieldKey);
191         }
192
193         JspFragment JavaDoc body = getJspBody();
194         if ( body != null ) {
195             body.invoke(null);
196         }
197     }
198
199 }
200
Popular Tags