|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry5.corelib.components.BeanDisplay
@SupportsInformalParameters public class BeanDisplay
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.
DataType
,
BeanModel
,
BeanEditForm
,
Grid
Component Parameters | ||||||
---|---|---|---|---|---|---|
Name | Description | Type | Flags | Default | Default Prefix | Since |
add | 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). | String | literal | |||
exclude | 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. | String | literal | |||
include | 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. | String | literal | |||
lean | If true, then the CSS class attribute on the dt and dd elements will be ommitted. | boolean | false | prop | ||
model | 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. | org. | prop | |||
object | 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. | Object | Required, Not Null | prop | ||
overrides | 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. | org. | componentResources | prop | ||
reorder | 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. | String | literal |
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 Summary | |
---|---|
BeanDisplay()
|
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()
public String getPropertyClass()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |