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="@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));
}
}