(Struts 2 Text jsp tag) to print out the name attribute in an HTML comment?-6ren"> (Struts 2 Text jsp tag) to print out the name attribute in an HTML comment?-当您使用 Struts 2 文本 jsp 标记,您从页面中的 .properties 文件中获取文本。 例如,如果 .properties 文件包含 foo.bar = This is the te-6ren">
gpt4 book ai didi

java - 如何覆盖 (Struts 2 Text jsp tag) to print out the name attribute in an HTML comment?

转载 作者:行者123 更新时间:2023-11-30 11:53:23 24 4
gpt4 key购买 nike

当您使用 <struts:text name="..."/> Struts 2 文本 jsp 标记,您从页面中的 .properties 文件中获取文本。

例如,如果 .properties 文件包含

foo.bar = This is the text.

jsp标签<struts:text name="foo.bar"/>会输出

This is the text.

现在我想要 <struts:text name="..."> 的所有实例在 webapp 中还可以在 HTML 注释中输出名称属性,如下所示:

<!-- foo.bar -->This is the text.

我尝试创建自己的 jsp 标记文件(代替 <struts:text> 使用),其中包含

<%@attribute name="name" required="true"%>

<!-- ${name} --><struts:text name="${name}"/>

但它不起作用,因为 <rtexprvalue>设置为 false对于 name struts:text 的属性标签。

有什么想法可以实现吗?

最佳答案

# PROPERTIES
copyright.year=2011

(B) : 覆盖默认主题 ( is acceptable )

标签.ftl

添加以下代码 <!-- ${parameters.name?html} -->

<!-- ${parameters.name?html} -->

<label<#rt/>
...
</label>

.jsp

<s:label key="copyright.year" />

HTML 输出:

2011

HTML 来源:

<!-- copyright.year -->
<label id="form_name_copyright_year">2011</label>

或(不推荐)

label.ftl只有4行代码

<#if parameters.nameValue??>
<!-- ${parameters.name?html} --><#rt/>
<@s.property value="parameters.nameValue"/><#t/>
</#if>

HTML 来源:

<!-- copyright.year -->2011

(A)

/**
* Overridden/replacement for {@link ActionSupport}.
*/
public class MyActionSupport extends ActionSupport {

public String text(String fieldName) {
return "<!-- " + fieldName + " --> " + getText(fieldName);
}
}


public class MyAction extends MyActionSupport {

}

.jsp

<s:property value="text('copyright.year')" escapeHtml="false" />

HTML 输出:

2011

HTML 来源:

<!-- copyright.year --> 2011

关于java - 如何覆盖<struts :text name ="..."/> (Struts 2 Text jsp tag) to print out the name attribute in an HTML comment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6307453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com