【问题标题】:How dows Tapestry set Headers of a grid component?Tapestry如何设置网格组件的Header?
【发布时间】:2013-06-06 15:00:42
【问题描述】:

我开始使用挂毯进行开发,我有一个问题。实际上,我对挂毯中的表格和表格标题有疑问。我知道如果你有一个用户类网格:

public class User {
    public String firstName;
    public String lastName;
}

<t:grid source="users" />

Tapestry 会生成类似于以下内容的 HTML:

<table>
    <thead>
        <tr>
            <th class="firstName">First Name</th>
            <th class="lastName">Last Name</th>
        </tr>
    </thead>
    <tbody>
        ...
        <tr>
            <td class="firstName">Traci</td>
            <td class="lastName">Lords</td>
        </tr>
        ...
    </tbody>
</table>

我的问题是 Tapestry 是如何设置标题的值的?

我的意思是 Tapestry 是如何从“firstName”类中设置值“First Name”的?

我希望我的问题很清楚。

谢谢。

【问题讨论】:

    标签: header grid tapestry tgrid


    【解决方案1】:

    Tapestry 使用反射来获取属性的名称(firstNamelastName),然后调用 TapestryInternalUtils.toUserPresentable(String id) 将其转换为更易于阅读的形式。

    来自toUserPresentable()javadocs:

    将字符串大写,并在每个大写字符(或大写字符序列)之前插入一个空格。因此“userId”变成了“User Id”等等。另外,将下划线转换为空格(并将后面的单词大写),因此“user_id”也变成了“User Id”。

    【讨论】:

    • 请注意,TapestryInternalUtils.toUserPresentable(..) 是最后的手段。 Tapestry 将首先尝试查找用户语言的本地化属性文件,然后查找 firstName-label、lastName-label 等属性。tapestry.apache.org/localization.html
    • 谢谢@uklance,您的回答是我在应用程序中发现的。根据您的消息,我猜正确的方法是使用带有“-label”后缀的属性文件,而不是让 Tapestry 从变量中获取名称?
    • @ibaneight 由您决定。课程用马:)。您可以选择在英语中依赖 TapestryInternalUtils.toUserPresentable(),但为其他语言提供覆盖。
    【解决方案2】:

    在我的应用程序中,我实际上有一个 FindUsers.tml 文件和 FindUsers.java 关联类,最后我有一个包含一些属性的 FindUsers.properties 文件。

    在我的 FindUsers.properties 中,我有 firstName-label=First Name 和 lastName-label=Last Name

    这些属性是在我的网格标题中选择的。

    我认为“-label”使挂毯选择此属性作为标题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多