Class BeanDisplay

  extended by org.apache.tapestry5.corelib.components.BeanDisplay

public class BeanDisplay
extends Object

Used to display the properties of a bean, using an underlying BeanModel. The output definition list: a <dl> element containing a series of <dt>/<dd> pairs. The property label is used as the <dt> and the property value (formatted as per the datatype) is the <dd>. Only properties that have a known data type are displayed.

The property id is used as the class attribute of the <dt> and <dd> element, allowing CSS customization per property. This does not occur when lean is bound to true.

The outer <dl> element has the CSS class "t-beandisplay".

See Also:
DataType, BeanModel, BeanEditForm, Grid
Component Parameters
NameDescriptionTypeFlagsDefaultDefault PrefixSince
addA comma-separated list of property names to be added to the org.apache.tapestry5.beaneditor.BeanModel (only used when a default model is created automatically).Stringliteral
excludeA comma-separated list of property names to be removed from the org.apache.tapestry5.beaneditor.BeanModel (only used when a default model is created automatically). The names are case-insensitive.Stringliteral
includeA comma-separated list of property names to be retained from the org.apache.tapestry5.beaneditor.BeanModel (only used when a default model is created automatically). Only these properties will be retained, and the properties will also be reordered. The names are case-insensitive.Stringliteral
leanIf true, then the CSS class attribute on the dt and dd elements will be ommitted.booleanfalseprop
modelThe model that identifies the parameters to be edited, 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. The add, include, exclude and reorder parameters are only applied to a default model, not an explicitly provided
objectThe object to be rendered; if not explicitly bound, a default binding to a property whose name matches this component's id will be used.ObjectRequired, Not Nullprop
overridesWhere 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
reorderA 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 orde. Only used when a default model is created automatically.Stringliteral

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:

public class User
    private long id;
    private String firstName;

    private String lastName;

    private int age;

    public long getId() { return id; }

    public void setId(long id) { = id; }

    public String getFirstName() { return firstName; }

    public void setFirstName(String firstName) { this.firstName = firstName; }

    public String getLastName() { return lastName; }

    public void setLastName(String lastName) { this.lastName = lastName; }

    public int getAge() { return age; }

    public void setAge(int age) { this.age = age; }

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

public class ViewUser
    private User user;

    public User getUser()
        return user;

    public void setUser(User user)
        this.user = user;

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


<html xmlns:t="" xmlns:p="tapestry:parameter">
        <h1>View User</h1>

        <t:beandisplay object="user">

The <p:lastName> 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").

CSS Customization:

The content is rendered as a

(definition list) element, containing
(term) and
(definition) elements.


will have the CSS class "t-beandisplay".


elements will have the property id as the CSS class name (i.e., "firstName", "lastName", etc.). This allows individual properties of the bean to have specific CSS rules applied.

The ":" after the property label is supplied via CSS.


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.

Constructor Summary
Method Summary
 String getPropertyClass()
 PropertyModel getPropertyModel()
          Returns the property model for the current property.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public BeanDisplay()
Method Detail


public PropertyModel getPropertyModel()
Returns the property model for the current property.


public String getPropertyClass()

Copyright © 2003-2012 The Apache Software Foundation.