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.
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().
The PropertySelection component provides Gender selection drop down list. In
this example the company stores Gender in a 1 CHAR database column, with
'U' for unspecified, 'F' for female and 'M' for male. The custom
GenderPropertySelectionModel class is used to map these internal
values to the display text: Unspecified, Female and Male.
Gender:
<form jwcid="detailsForm">
Gender: <span jwcid="selectGender"/>
</form>
<bean name="genderSelectModel" class="GenderPropertySelectionModel"/>
<component id="detailsForm" type="Form">
<binding name="listener" expression="listeners.formSubmit"/>
</component>
<component id="selectGender" type="PropertySelection">
<binding name="model" expression="beans.genderSelectModel"/>
<binding name="value" expression="clothingItem"/>
</component>
public class DetailsPage extends BasePage {
private String gender;
public String getGender() { return gender; }
public void setGender(String value) {
gender = value;
fireObservedChange("gender", value);
}
public void detach() {
gender = null;
super.detach();
}
public void formSubmit(IRequestCycle cycle) {
// Process form submission
}
}
public class GenderPropertySelectionModel implements IPropertySelectionModel {
public int getOptionCount() { return 3; }
public Object getOption(int index) {
if (index == 0) {
return "U"
} else if (index == 1) {
return "F"
} else {
return "M";
}
}
public String getLabel(int index) {
if (index == 0) {
return "Unspecified";
} else if (index == 1) {
return "Female";
} else {
return "Male";
}
}
public String getValue(int index) { return Integer.toString(index); }
public Object translateValue(String value) {
return getOption(Integer.parseInt(value));
}
}
Provides list of clothing items for the user to select. When the user selects a
cloting item from the list the description, label and price is automatically
updated. The list of clothing items would typically be loaded from a database.
Note the Script SelectSubmit is used to automatically
submit the form when user selects an item. Alternatively in version 2.2 and
latter you can simply set the component's 'submitOnChange' property to true.
Item:
Description: Cotton full length Summer dress
Label: CountryClub
Price: $89.95
<form jwcid="purchageForm">
Item: <span jwcid="selectItem"/> <span jwcid="itemOnChange"/>
<p>
Description: <span jwcid="insertDescription"/>
<p>
Label: <span jwcid="insertLabel"/>
<p>
Price: $<span jwcid="insertPrice"/>
</form>
<component id="purchaseForm" type="Form">
<binding name="listener" expression="listeners.formSubmit"/>
</component>
<component id="selectItem" type="PropertySelection">
<binding name="model" expression="itemSelectionModel"/>
<binding name="value" expression="clothingItem"/>
</component>
<component id="itemOnChange" type="Script">
<static-binding name="script">/net/sf/tapestry/form/SelectSubmit.script</static-binding>
<binding name="component" expression="components.itemSelect"/>
</component>
<component id="insertDescription" type="Insert">
<binding name="value" expression="clothingItem.description"/>
</component>
<component id="insertLabel" type="Insert">
<binding name="value" expression="clothingItem.label"/>
</component>
<component id="insertPrice" type="Insert">
<binding name="value" expression="clothingItem.price"/>
</component>
public class PurchagePage extends BasePage {
private String clothingItem;
private ItemSelectionModel itemSelectionModel;
public Item getClothingItem() { return clothingItem; }
public void setClothingItem(Item value) {
clothingItem = value;
fireObservedChange("clothingItem", value);
}
public ItemSelectionModel getItemSelectionModel() {
return itemSelectionModel;
}
public ItemSelectionModel setItemSelectionModel(ItemSelectionModel value) {
itemSelectionModel = value;
fireObservedChange("itemSelectionModel", value);
}
public void detach() {
clothingItem = null;
itemSelectionModel = null;
super.detach();
}
public void formSubmit(IRequestCycle cycle) {
// Process form submission
}
}
public class Item implements Serializable {
private Integer id;
private String name;
private String description;
private String label;
private String price;
public Item(Integer 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 int getDescription() { return description; }
public int getLabel() { return label; }
public int getPrice() { return price; }
}
public class ItemSelectionModel implements IPropertySelectionModel, Serializable {
private List itemList;
public ItemPropertySelectionModel(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) { Integer.toString(index); }
public Object translateValue(String value) {
return getOption(Integer.parseInt(value));
}
}