1 28 29 package com.caucho.jstl.el; 30 31 import com.caucho.el.Expr; 32 import com.caucho.jsp.PageContextImpl; 33 import com.caucho.jstl.ChooseTag; 34 import com.caucho.util.L10N; 35 36 import javax.el.ELException; 37 import javax.servlet.jsp.JspException ; 38 import javax.servlet.jsp.tagext.Tag ; 39 import javax.servlet.jsp.tagext.TagSupport ; 40 41 44 public class WhenTag extends TagSupport { 45 private static L10N L = new L10N(WhenTag.class); 46 47 private Expr _testExpr; 48 49 54 public void setTest(Expr test) 55 { 56 _testExpr = test; 57 } 58 59 62 public int doStartTag() 63 throws JspException 64 { 65 try { 66 Tag parent = getParent(); 67 68 if (! (parent instanceof ChooseTag)) 69 throw new JspException (L.l("c:when tag must be contained in a c:choose tag.")); 70 71 ChooseTag chooseTag = (ChooseTag) parent; 72 73 if (chooseTag.isMatch()) 74 return SKIP_BODY; 75 76 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 77 boolean test = _testExpr.evalBoolean(pageContext.getELContext()); 78 79 if (test) { 80 chooseTag.setMatch(); 81 82 return EVAL_BODY_INCLUDE; 83 } 84 else 85 return SKIP_BODY; 86 } catch (ELException e) { 87 throw new JspException (e); 88 } 89 } 90 } 91 | Popular Tags |