ibaneight
ibaneight

Reputation: 1445

How dows Tapestry set Headers of a grid component?

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.

Upvotes: 1

Views: 821

Answers (2)

ibaneight
ibaneight

Reputation: 1445

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.

Upvotes: 0

Steve Eynon
Steve Eynon

Reputation: 5139

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

Upvotes: 3

Related Questions