KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > menu > context > ItemSetTag


1 package com.blandware.atleap.webapp.taglib.core.menu.context;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.JspTagException JavaDoc;
5 import javax.servlet.jsp.PageContext JavaDoc;
6 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
7 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
8 import java.io.IOException JavaDoc;
9
10 /**
11  * <p>Marks logical group of menu items, which are included in the context menu.
12  * This tag is usable within various iteration tags to mark logical row of
13  * generated table. This tag is needed, because context menu support tags need
14  * to know where set of items corresponding to some data row ends and next set
15  * begins.
16  * <br />
17  * This tag is only valid when nested within <em>contextMenu</em> tag.
18  * </p>
19  * <p><a HREF="ItemSetTag.java.htm"><i>View Source</i></a></p>
20  *
21  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
22  * @version $Revision: 1.4 $ $Date: 2005/10/12 13:35:03 $
23  * @see ContextMenuTag
24  * @see ItemTag
25  * @jsp.tag name="itemSet"
26  * body-content="scriptless"
27  */

28 public class ItemSetTag extends SimpleTagSupport JavaDoc {
29
30     // ~ Static fields
31

32     /**
33      * Part of context key, under which number of this tag is stored. Full key is generated using ID of parent ContextMenuTag
34      */

35     protected static final String JavaDoc INDEX_KEY_PART = "com.blandware.atleap.webapp.taglib.core.menu.context.ItemSetTag.INDEX";
36
37     /**
38      * Index of currently processed row
39      */

40     protected Integer JavaDoc index;
41
42     /**
43      * Creates new instance of ItemSetTag
44      */

45     public ItemSetTag() {
46     }
47
48     /**
49      * Returns index of currently processed row
50      *
51      * @return index
52      */

53     public Integer JavaDoc getIndex() {
54         return index;
55     }
56
57     /**
58      * Processes the tag
59      *
60      * @throws JspException
61      * @throws IOException
62      */

63     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
64         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
65
66         // search for parent ContextMenuTag
67
ContextMenuTag parentContextMenuTag = (ContextMenuTag) findAncestorWithClass(this, ContextMenuTag.class);
68
69         if ( parentContextMenuTag == null ) {
70             throw new JspTagException JavaDoc("This tag is only valid when nested within 'contextMenu' tag");
71         }
72
73         // search for index
74

75         // construct key first
76
String JavaDoc key = INDEX_KEY_PART + "[" + parentContextMenuTag.getTagId() + "]";
77
78         // get index
79
index = (Integer JavaDoc) pageContext.getAttribute(key, PageContext.REQUEST_SCOPE);
80         if ( index == null ) {
81             index = new Integer JavaDoc(0);
82         } else {
83             index = new Integer JavaDoc(index.intValue() + 1);
84         }
85         // save index in request
86
pageContext.setAttribute(key, index, PageContext.REQUEST_SCOPE);
87
88         // process body
89
JspFragment JavaDoc body = getJspBody();
90         if ( body != null ) {
91             body.invoke(null);
92         }
93
94     }
95
96 }
97
Popular Tags