KickJava   Java API By Example, From Geeks To Geeks.

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


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.grid.util.Grid;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.JspTagException JavaDoc;
22 import javax.servlet.jsp.PageContext JavaDoc;
23 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
24 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 /**
28  * <p>Body of this tag will be rendered if and only if filter by field
29  * specified in enclosing filter tag has been enabled.
30  * <br />
31  * This tag is only valid when nested within some filter tag
32  * </p>
33  * <p><a HREF="FilterEnabledTag.java.htm"><i>View Source</i></a></p>
34  *
35  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
36  * @version $Revision: 1.8 $ $Date: 2005/10/12 13:34:56 $
37  * @jsp.tag name="filterEnabled"
38  * body-content="scriptless"
39  * @see com.blandware.atleap.webapp.taglib.core.grid.NumberFilterTag
40  * @see com.blandware.atleap.webapp.taglib.core.grid.DateFilterTag
41  * @see com.blandware.atleap.webapp.taglib.core.grid.StringFilterTag
42  * @see com.blandware.atleap.webapp.taglib.core.grid.SetFilterTag
43  */

44 public class FilterEnabledTag extends SimpleTagSupport JavaDoc {
45
46     /**
47      * Processes the tag
48      *
49      * @throws JspException
50      * @throws IOException
51      */

52     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
53
54         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
55
56         // This tag is only valid when nested within any 'filter' tag, so check this
57

58         BaseFilterTag parentFilterTag = (BaseFilterTag) findAncestorWithClass(this, BaseFilterTag.class);
59         if ( parentFilterTag == null ) {
60             JspTagException JavaDoc e = new JspTagException JavaDoc("Parent tag is invalid! This tag is only valid when nested within 'filter' tag");
61             throw e;
62         }
63
64         // Render body if enclosing filter is enabled
65

66         String JavaDoc fieldName = parentFilterTag.getFieldName();
67
68         GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class);
69         Grid grid = parentGridTag.getGrid();
70
71         if ( grid.isFilterEnabled(fieldName) ) {
72             JspFragment JavaDoc body = getJspBody();
73             if ( body != null ) {
74                 body.invoke(null);
75             }
76         }
77     }
78
79 }
80
Popular Tags