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().
<form jwcid="detailsForm">
Gender: <span jwcid="selectGender"/>
</form>
<component id="detailsForm" type="Form">
<binding name="listener" expression="listeners.formSubmit"/>
</component>
<component id="selectGender" type="PropertySelection">
<binding name="model" expression="@com.mycorp.DetailsPage@GENDER_MODEL"/>
<binding name="value" expression="gender"/>
</component>
package com.mycorp;
public class DetailsPage extends BasePage {
public static final IPropertySelectionModel GENDER_MODEL =
new StringPropertySelectionModel(new String[] { "Unspecified", "Female", "Male" });
private String gender;
public String getGender() { return gender; }
public void setGender(String value) {
gender = value;
}
public void detach() {
gender = null;
super.detach();
}
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="purchageForm">
Item: <span jwcid="selectItem"/>
<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"/>
<binding name="submitOnChange" expression="true"/>
</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));
}
}