PageLink Index Radio

PropertySelection
org.apache.tapestry.form.PropertySelection
Color
 

Description
Creates form elements that allow a property of an object to be set from a drop-down list.

Uses a model to map between Java values that will be assigned, and textual labels that will appear in the HTML response.

There is a range property selection models you can use, including StringPropertySelectionModel and EnumPropertySelectionModel. You can also create your own model, as illustrated in the Examples below.

Note that complex value Objects need to properly implement the Object.equals() method if the correct initial item is to be displayed.

Informal parameters are applied to the <select> tag.  To have greater control over the <option> tags, you must use the Select and Option components.

See Also
Select, Option, Radio, RadioGroup, Form, Script
Parameters
Name Type Direction Required Default Description
value Object in-out yes   The property to set. During rendering, this property is read, and sets the default value of the selection (if it is null, no element is selected). When the form is submitted, this property is updated based on the new selection.
model IPropertySelectionModel in yes   The model provides a list of possible labels, and matches those labels against possible values that can be assigned back to the property.
disabled boolean in no false Controls whether the <select> is active or not. A disabled PropertySelection does not update its value parameter. Corresponds to the "disabled" HTML attribute.
submitOnChange boolean in no false If true, then additional JavaScript is added to submit the containing form when select is changed. Equivalent to specifying a JavaScript event handler of this.form.submit().

Body: removed
Informal parameters: allowed
Reserved parameters: "name"

Examples

The PropertySelection component provides Gender selection drop down list using a StringPropertySelectionModel

Gender:

<form jwcid="@Form" listener="ognl:listeners.formSubmit">
 Gender: <span jwcid="@PropertySelection" model="ognl:@com.mycorp.DetailsPage@GENDER_MODEL" value="ognl:gender"/>
</form>

<property-specification name="gender" type="java.lang.String"/>
package com.mycorp; public abstract class DetailsPage extends BasePage { public static final IPropertySelectionModel GENDER_MODEL = new StringPropertySelectionModel(new String[] { "Unspecified", "Female", "Male" }); public abstract String getGender(); public void formSubmit(IRequestCycle cycle) { // Process form submission String genderSelection = getGender(); .. } }

Provides list of clothing items for the user to select. When the user selects a cloting item from the list the description the label and price is automatically updated. The list of clothing items would typically be loaded from a database.

This example uses the component's submitOnChange property to automatically submit the form when a HTML <select> onchange event occurs. The page's clothing item property is then updated and the new cloting item information is displayed by the description, label and price Insert components.

Item:

Description: Cotton full length Summer dress

Label: CountryClub

Price: $89.95

<form jwcid="@Form" listener="ognl:listeners.formSubmit">
 Item: <span jwcid="selectItem"/>
 <p>
 Description: <span jwcid="@Insert" value="ognl:clothingItem.description"/>
 <p>
 Label: <span jwcid="@Insert" value="ognl:clothingItem.label"/>
 <p>
 Price: $<span jwcid="@Insert" value="ognl:clothingItem.price"/>
</form>


<component id="selectItem" type="PropertySelection">
    <binding name="model" expression="itemSelectionModel"/>
    <binding name="value" expression="clothingItem"/>
    <binding name="submitOnChange" expression="true"/>
</component>

<property-specification name="clothingItem" type="Item" persistent="yes"/>
<property-specification name="itemSelectionModel" type="ItemSelectionModel" persistent="yes"/>
public abstract class PurchagePage extends BasePage { public abstract Item getClothingItem(); public abstract void setClothingItem(Item value); public abstract ItemSelectionModel getItemSelectionModel(); public void setItemSelectionModel(ItemSelectionModel value); public void formSubmit(IRequestCycle cycle) { // Process form submission } } public class Item implements Serializable { private int id; private String name; private String description; private String label; private String price; public Item(int id, String name, String desc, String label, String price) { this.id = id; this.name = name; this.description = desc; this.label = label; this.price = price; } public int getId() { return id; } public String getName() { return name; } public String getDescription() { return description; } public String getLabel() { return label; } public String getPrice() { return price; } } public class ItemSelectionModel implements IPropertySelectionModel, Serializable { private List itemList; public ItemSelectionModel(List itemList) { this.itemList = itemList; } public int getOptionCount() { return itemList.size(); } public Object getOption(int index) { return itemList.get(index); } public String getLabel(int index) { return ((Item) itemList.get(index)).getName(); } public String getValue(int index) { return Integer.toString(index); } public Object translateValue(String value) { return getOption(Integer.parseInt(value)); } }

PageLink Index Radio