@SupportsInformalParameters public class BeanDisplay extends Object
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".DataType
,
BeanModel
,
BeanEditForm
,
Grid
Name | Type | Flags | Default | Default Prefix |
---|---|---|---|---|
add | String | literal | ||
A 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). | ||||
exclude | String | literal | ||
A 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. | ||||
include | String | literal | ||
A 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. | ||||
lean | boolean | false | prop | |
If true, then the CSS class attribute on the <dt> and <dd> elements will be ommitted. | ||||
model | org. | prop | ||
The 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 one. | ||||
object | Object | Required, Not Null | prop | |
The object to be rendered; if not explicitly bound, a default binding to a property whose name matches this component's id will be used. | ||||
overrides | org. | componentResources | prop | |
Where 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. | ||||
reorder | String | literal | ||
A 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. |
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 { @NonVisual private long id; private String firstName; private String lastName; private int age; public long getId() { return id; } public void setId(long id) { this.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 { @Persist 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="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter"> <body> <h1>View User</h1> <t:beandisplay object="user"> <p:lastName> ${bean.lastname.toUpperCase()} </p:lastName> </t:beandisplay> </body> </html>
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").
The content is rendered as a
The
The
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 and Description |
---|
BeanDisplay() |
Modifier and Type | Method and Description |
---|---|
BeanModel |
getModel() |
String |
getPropertyClass() |
PropertyModel |
getPropertyModel()
Returns the property model for the current property.
|
public BeanDisplay()
public PropertyModel getPropertyModel()
public String getPropertyClass()
${project.version} - Copyright © 2003-2015 The Apache Software Foundation.