1 package com.blandware.atleap.webapp.taglib.core.menu.context; 2 3 import javax.servlet.jsp.JspException ; 4 import javax.servlet.jsp.JspTagException ; 5 import javax.servlet.jsp.PageContext ; 6 import javax.servlet.jsp.tagext.JspFragment ; 7 import javax.servlet.jsp.tagext.SimpleTagSupport ; 8 import java.io.IOException ; 9 10 28 public class ItemSetTag extends SimpleTagSupport { 29 30 32 35 protected static final String INDEX_KEY_PART = "com.blandware.atleap.webapp.taglib.core.menu.context.ItemSetTag.INDEX"; 36 37 40 protected Integer index; 41 42 45 public ItemSetTag() { 46 } 47 48 53 public Integer getIndex() { 54 return index; 55 } 56 57 63 public void doTag() throws JspException , IOException { 64 PageContext pageContext = (PageContext ) getJspContext(); 65 66 ContextMenuTag parentContextMenuTag = (ContextMenuTag) findAncestorWithClass(this, ContextMenuTag.class); 68 69 if ( parentContextMenuTag == null ) { 70 throw new JspTagException ("This tag is only valid when nested within 'contextMenu' tag"); 71 } 72 73 75 String key = INDEX_KEY_PART + "[" + parentContextMenuTag.getTagId() + "]"; 77 78 index = (Integer ) pageContext.getAttribute(key, PageContext.REQUEST_SCOPE); 80 if ( index == null ) { 81 index = new Integer (0); 82 } else { 83 index = new Integer (index.intValue() + 1); 84 } 85 pageContext.setAttribute(key, index, PageContext.REQUEST_SCOPE); 87 88 JspFragment body = getJspBody(); 90 if ( body != null ) { 91 body.invoke(null); 92 } 93 94 } 95 96 } 97 | Popular Tags |