I'm a little confused if which one is evaluated first. jstl or my custom taglib.
Here is some snippets.
<taglib>
...
<tag>
<name>my_tag</name>
<tagclass>MyTagLib</tagclass>
<bodycontent>JSP</bodycontent开发者_如何学编程>
<attribute>
<name>attr1</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</taglib>
tried to use it in jsp by:
...
pageContext.setAttribute("val", "actualValue");
...
<t:my_tag attr1="${val}"/>
public MyTagLib extends TagSupport{
private String attr1;
public void setAttr1( String str ){
attr1 = str; // this returns "${val}". i was expecting "actualValue".
}
...
}
I wonder how to access the actual value of val?
Here's an article that addresses this issue in a coherent fashion:
http://www.informit.com/articles/article.aspx?p=30946&seqNum=9
In summary, the attributes of a custom tag are not processed by the EL evaluator by default. If you want this to be done, you need to code the tag handler class to do this.
If you don't want to go to the bother of doing this, you can use <%= ... %>
expressions instead.
Runtime expression evaluation is what allows you to evaluate Java expressions inside of <%= ...%>
for your custom tag parameters. If you use the JSTL expression language (EL), you don't use the Java expression tag. They are two separate ways to refer to dynamic content for custom tag attributes. To use the JSTL EL, you have to build your custom tag such that it has EL support in it.
For the EL evaluation mechanism, check out the class org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager
in the Jakarta Standard Taglib
精彩评论