1

I was starting developping with tapestry and I have a question. Actually I have a question about the tables in tapestry and the headers of the tables. I know that if you have a Grid of User classes:

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

<t:grid source="users" />

Tapestry would produce HTML similar to:

<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>

And my question is how did Tapestry set the values of the headers?

I mean how did tapestry set the value "First Name" from the class "firstName"?

I hope my question is clear.

Thank you.

ibaneight
  • 1,335
  • 2
  • 11
  • 15

2 Answers2

3

Tapestry uses reflection to get the names of your properties (firstName and lastName) then calls TapestryInternalUtils.toUserPresentable(String id) to convert it to a more human readable form.

From toUserPresentable() javadocs:

Capitalizes the string, and inserts a space before each upper case character (or sequence of upper case characters). Thus "userId" becomes "User Id", etc. Also, converts underscore into space (and capitalizes the following word), thus "user_id" also becomes "User Id".

Steve Eynon
  • 4,979
  • 2
  • 30
  • 48
  • Note that TapestryInternalUtils.toUserPresentable(..) is a last resort. Tapestry will first try to find a localized property file for the user's language and will look for properties for firstName-label, lastName-label etc. http://tapestry.apache.org/localization.html – lance-java Jun 07 '13 at 07:57
  • Thank you @uklance your answer is what I've discovered in my application. According to your message i guess that the correct way is to use a properties file with the "-label" suffix, better than let tapestry get the name from the Variable? – ibaneight Jun 07 '13 at 10:21
  • @ibaneight the choice is up to you. Horses for courses :). You might choose to rely on TapestryInternalUtils.toUserPresentable() for english but provide overrides for other languages. – lance-java Jun 07 '13 at 11:46
0

In my application I actually have a FindUsers.tml file and also the FindUsers.java associated class, and finally I've got a FindUsers.properties file with some properties.

In my FindUsers.properties i've got the firstName-label=First Name and lastName-label=Last Name

and these properties are selected in my grid headers.

I think the "-label" makes that tapestry selects this properties as headers.

ibaneight
  • 1,335
  • 2
  • 11
  • 15