Variable in an attribute in Struts custom tag

a 夏天 提交于 2020-01-25 12:34:04

问题


I am trying to use a variable inside a custom Struts tag something like follows -

for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
    name = currentMacro.<some-operation>

<html:mce name = "hmtl_<%= name %>" />

Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.

Is there any any way to accomplish this in this case?

Thanks.


回答1:


Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.

<html:mce name="html_${name}"/>

But why use scriptlets? There's rarely (ever?) a good reason.




回答2:


Since we are taking about a custom tag, my guess is that in the TLD file there isn't the rtexprvalue option set to true for that particular tag attribute:

<attribute>
   <name>name</name>
   <rtexprvalue>true</rtexprvalue>
   .......
</attribute>

The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.

If set to "false" it means that the attribute has a static value which is evaluated at translation; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".

If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.



来源:https://stackoverflow.com/questions/7389308/variable-in-an-attribute-in-struts-custom-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!