开发者

Is there any good reason to use <rtexprvalue>false</rtexprvalue> in JSP tags?

开发者 https://www.devze.com 2022-12-24 06:07 出处:网络
Is there any good reason to disal开发者_如何学Clow scriptlet or EL expression to be inserted as attribute value?

Is there any good reason to disal开发者_如何学Clow scriptlet or EL expression to be inserted as attribute value?

Let's say we have tag:

<tag>
    <name>mytag</name>
    <tag-class>org.apache.beehive.netui.tags.tree.Tree</tag-class>
    <attribute>
        <name>attr</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
        <type>boolean</type>
    </attribute>
</tag>

What could be a good reason for dissallowing the below?

<my:mytag attr="${setting}" />


I'd say it is mostly a backwards-compatibility measure, just like the ability to turn off EL completely for a given JSP.

Maybe the tag library existed before EL, and uses the special syntax ${} for its own purposes. Maybe the attribute value frequently takes values that include a literal ${}.

Without such a setting, existing code (in the tag library or the JSP) would need to be modified in order to still work after upgrading to the latest version of the Servlet spec.


There might potentially be attributes (eg. id to refer to the tag itself) that it's not suitable to set at run-time. You could probably come up with a scenario where you really wanted ${} to mean plain text, or where any EL content was evaluated manually in some kind of custom context.

But I think the real reason for the switch is backwards compatibility. Custom tags predate JSP's built-in support for the EL; changing the definition underneath a taglib so that ${} now has a special meaning is likely to break existing templates' use of that tag. Safer to default to rtexprvalue-false for back-compat and let new taglibs for JSP 2.0 specify they want the new behaviour.

[yes. what Thilo said. :-)]

0

精彩评论

暂无评论...
验证码 换一张
取 消