1 16 17 package javax.servlet.jsp.jstl.core; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.JspTagException ; 21 import javax.servlet.jsp.PageContext ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 42 43 public abstract class ConditionalTagSupport 44 extends TagSupport 45 { 46 49 57 protected abstract boolean condition() throws JspTagException ; 58 59 60 63 69 public ConditionalTagSupport() { 70 super(); 71 init(); 72 } 73 74 75 78 81 public int doStartTag() throws JspException { 82 83 result = condition(); 85 86 exposeVariables(); 88 89 if (result) 91 return EVAL_BODY_INCLUDE; 92 else 93 return SKIP_BODY; 94 } 95 96 99 public void release() { 100 super.release(); 101 init(); 102 } 103 104 107 private boolean result; private String var; private int scope; 111 112 115 121 public void setVar(String var) { 122 this.var = var; 123 } 124 125 130 public void setScope(String scope) { 131 if (scope.equalsIgnoreCase("page")) 132 this.scope = PageContext.PAGE_SCOPE; 133 else if (scope.equalsIgnoreCase("request")) 134 this.scope = PageContext.REQUEST_SCOPE; 135 else if (scope.equalsIgnoreCase("session")) 136 this.scope = PageContext.SESSION_SCOPE; 137 else if (scope.equalsIgnoreCase("application")) 138 this.scope = PageContext.APPLICATION_SCOPE; 139 } 141 142 143 146 private void exposeVariables() { 148 if (var != null) 149 pageContext.setAttribute(var, new Boolean (result), scope); 150 } 151 152 private void init() { 154 result = false; var = null; 156 scope = PageContext.PAGE_SCOPE; 157 } 158 } 159 | Popular Tags |