Struts 自定义标签中属性中的变量
我正在尝试在自定义 Struts 标签内使用变量,如下所示 -
for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
name = currentMacro.<some-operation>
<html:mce name = "hmtl_<%= name %>" />
类似这样。但是<%=name%>不被变量值替换。当我将变量与纯 HTML 标签一起使用时,它可以工作。
在这种情况下有什么办法可以实现这一点吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 JSP EL(假设是 JSP 2.0,并且您将“名称”放入范围中)。您还可以检查 TLD 是否允许 rtexprs。
<代码>
但为什么要使用 scriptlet?很少(曾经?)有充分的理由。
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.
由于我们正在考虑自定义标签,我的猜测是在 TLD 文件中没有将特定标记属性的
rtexprvalue
选项设置为 true:rtexprvalue
指定可以在运行时动态评估属性值。如果设置为“false”,则意味着该属性具有静态值,该值在 翻译;如果设置为“true”,则意味着该值可以在运行时动态确定。默认为“假”。
如果该 scriptlet 不起作用,则很可能意味着
rtexprvalue
为 false。如果您无权更改它,则表达式将不适用于该特定属性。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: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.