以下是我自己写的标签处理器类,用来实现嵌套的if_else,如
<my:choose>
<my:if condition="...">
...
</my:if>
<my:else>
<my:choose>
<my:if condition="...">
...
</my:if>
<my:else>
...
</my:else>
</my:choose>
</my:else>
<my:choose>
但实际使用的时候结果并不正确,请问是我的标签处理器写得有问题吗?
- Java code
public class MyChooseTag extends BodyTagSupport{ private boolean executed; public void setExecuted(boolean ed){ this.executed=ed; } public boolean getExecuted(){ return executed; } public int doStartTag() throws JspException{ executed=false; return EVAL_BODY_INCLUDE; } public int doEndTag() throws JspException{ return EVAL_PAGE; }}public class MyIfTag extends BodyTagSupport{ private boolean condition; public void setCondition(boolean condition){ this.condition=condition; } public int doStartTag() throws JspException{ MyChooseTag parent=(MyChooseTag)this.getParent(); if(condition){ parent.setExecuted(true); return EVAL_BODY_INCLUDE; } else{ parent.setExecuted(false); return SKIP_BODY; } } public int doEndTag() throws JspException{ return EVAL_PAGE; }}public class MyElseTag extends BodyTagSupport{ public int doStartTag() throws JspException{ MyChooseTag parent=(MyChooseTag)getParent(); if(parent.getExecuted()){ return SKIP_BODY; } else{ return EVAL_BODY_INCLUDE; } }}
求教啊……多谢多谢!!
------解决方案--------------------
EL 表达式是从作用域取值吧,你这个算什么意思
------解决方案--------------------
主要是检查下是不是启用了EL为啥没生效。