如何使用 Struts2 属性文件条目填充 displaytag 列标题?

How do you populate a displaytag column title with a Struts2 properties file entry?

在 Struts2 中,您可以使用属性文件中的值填充组件的标签。属性文件必须与将提供 JSP 的 Struts2 操作 Class 同名,并且与该操作 Class.[=13= 位于同一文件夹中]

<s:textfield key="field.label.casereference" name="caseReference" />

我想对 displaytag 列做同样的事情。但是好像不行。

displaytag 中的列有一个名为 titleKey 的属性,可以让您执行此操作。但是好像不行。

<display:table class="displaytag" id="Table2" name="getResultlistCases" clearStatus="true" requestURI="/AbsHearingSrALJ_homePage.action">
    <display:column style="width:8%;" property="aljNum" titleKey="field.label.aljNumber" />
    <display:column style="width:9%;" property="location" titleKey="field.label.location" />
    <display:column style="width:10%;" property="caseName" titleKey="field.label.caseName" />
    <display:column style="width:25%;" property="scheduledTime" titleKey="field.label.scheduledTime" />

titleKey 字段未从属性文件中获取值。当我使用 Struts2 文本字段的键字段时有效,但不适用于显示标签的列的 titleKey 字段。

有谁知道是否可以让它工作?

Displaytag provides an interface I18nResourceProvider with a few ready to use implementations which match the behaviour of common frameworks. This is configured in displaytag.properties using the locale.provider key. By default the JSTL implementation is used.

并且在 org.displaytag.localization.I18nJstlAdapter 描述中:

It will make the titleKey attribute of column tag works the same as fmt:message's key property. This tag must be the descendant of a fmt:bundle tag in order to use the titleKey.

所以你应该使用以下方法(我测试过 - 它有效):

   <fmt:bundle basename="action.HelloWorld">
      <display:table name="test">
         <display:column property="aljNum" titleKey="field.label.aljNumber" />
      </display:table>
   </fmt:bundle>

还请记住,fmt:bundle 中的 "basename" 是没有“.properties”扩展名的完全限定资源名称。