org.apache.tapestry.corelib.components.BeanDisplay

Used to display the properties of a bean, using an underlying org.apache.tapestry.beaneditor.BeanModel. The output is a series of div elements for the property names and property values. Only properties that have a known data type are displayed.

[JavaDoc]

Component Parameters

NameTypeFlagsDefaultDefault PrefixDescription
excludeStringliteralA comma-separated list of property names to be removed from the org.apache.tapestry.beaneditor.BeanModel. The names are case-insensitive.
includeStringliteralA comma-separated list of property names to be retained from the org.apache.tapestry.beaneditor.BeanModel. Only these properties will be retained, and the properties will also be reordered. The names are case-insensitive.
leanbooleanfalsepropIf true, then span tags around each output property will be omitted. If false, then a span tag (to identify the id of each property as the CSS class attribute) will be included.
modelorg.apache.tapestry.beaneditor.BeanModelpropThe model that identifies the parameters to be displayed, their order, and every other aspect. If not specified, a default bean model will be created from the type of the object bound to the object parameter.
objectObjectRequiredpropThe object to be rendered; if not explicitly bound, a default binding to a property whose name matches this component's id will be used.
overridesorg.apache.tapestry.ComponentResourcescomponentResourcespropWhere to search for local overrides of property display blocks as block parameters. Further, the container of the overrides is used as the source for overridden validation messages. This is normally the component itself, but when the component is used within a BeanEditForm, it will be the BeanEditForm's block parameter that will be searched.
reorderStringliteralA comma-separated list of property names indicating the order in which the properties should be presented. The names are case insensitive. Any properties not indicated in the list will be appended to the end of the display order.

Related Components

Examples

Here, we'll display a User object, consisting of a first name, last name and age. We'll also customize the output of the last name property, to display the name in all upper-case. The result:

User.java

public class User
{
    private long _id;
    
    private String _firstName;

    private String _lastName;

    private int _age;

    public long getId() { return _id; }

    @NonVisual
    public void setId(long id) { _id = id; }

    public String getFirstName() { return _firstName; }

    public void setFirstName(String firstName) { _firstName = firstName; }

    public String getLastName() { return _lastName; }

    public void setLastName(String lastName) { _lastName = lastName; }

    public int getAge() { return _age; }

    public void setAge(int age) { _age = age; }
}

The @NonVisual annotation prevents the id property from being displayed.

ViewUser.java

public class ViewUser
{
    @Persist
    private User _user;

    public User getUser()
    {
        return _user;
    }

    public void setUser(User user)
    {
        _user = user;
    }
}

Presumably, some other page is obtaining the User instance and invoking the setUser() method.

ViewUser.tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <body>
        <h1>View User</h1>

        <t:beandisplay object="user">
            <t:parameter name="lastname">
                ${bean.lastname.toUpperCase()}
            </t:parameter>
        </t:beandisplay>
    </body>
</html>

The <t:parameter> element is an override for the property. The name is matched against a property of the bean.

Here we are leveraging the ability to invoke methods as part of a property expression. We are also highlighting Tapestry's case insensitivity ("lastname" vs. "lastName").

Notes

You can re-order the properties using the reorder parameter:

<t:beandisplay object="user" reorder="lastname,firstname"/>

You can accomplish the same thing by changing the order of the getter methods in the bean class. The default order for properties is not alphabetical, it is the order of the getter methods.

You can also remove properties with the exclude parameter, which is equivalent to the @NonVisual annotation.

You might find <t:beandisplay object="this"/> useful on occasion. It will display all the properties of the current page.

As with the BeanEditForm component, you may override the labels displayed for the fields using the page's message catalog.

Please refer to the PageLink component documentation for an alternate way to manage the _user field.


Back to index