KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.blandware.atleap.webapp.taglib.core.grid.util.SortField;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspTagException JavaDoc;
23 import javax.servlet.jsp.PageContext JavaDoc;
24 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
25 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 /**
29  * <p>Body of this tag will be rendered if and only if sort order by field
30  * specified in parent SortTag is descending.
31  * <br />
32  * This tag is only valid when nested within <em>sort</em> tag
33  * <p><a HREF="SortDescTag.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.7 $ $Date: 2005/09/21 13:46:00 $
37  * @see SortTag
38  * @see SortAscTag
39  * @jsp.tag name="sortDesc"
40  * body-content="scriptless"
41  */

42 public class SortDescTag extends SimpleTagSupport JavaDoc {
43
44     /**
45      * Processes the tag
46      *
47      * @throws JspException
48      * @throws IOException
49      */

50     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
51
52         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
53
54         SortTag parentSortTag = (SortTag) findAncestorWithClass(this, SortTag.class);
55         if ( parentSortTag == null ) {
56             JspTagException JavaDoc e = new JspTagException JavaDoc("Parent tag is invalid! This tag is only valid when nested within 'sort' tag");
57             throw e;
58         }
59
60         String JavaDoc fieldName = parentSortTag.getFieldName();
61
62         GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class);
63         Grid grid = parentGridTag.getGrid();
64
65         SortField sortField = grid.getSortFieldByFieldName(fieldName);
66         if ( sortField != null && !sortField.isOrderAscending() ) {
67             JspFragment JavaDoc body = getJspBody();
68             if ( body != null ) {
69                 body.invoke(null);
70             }
71         }
72     }
73 }
74
Popular Tags