Reputation: 13724
I have a Tapestry PropertyModel for gender. Right now the dropdown just shows Male and Female because those are the only values in my model. I'd like to add a "Choose an Option" option. Is there a standard way to do this without having to add a fake value to my model? I'd also like it to be smart enough to know that if the field is required, they can't leave it set to "Choose an Option".
Upvotes: 2
Views: 200
Reputation: 5159
On Tapestry 5 you just set the blankLabel property.
On Tapestry 4 it is easier to just add that feature to your PropertyModel or wrap it on a LabeledPropertySelectionModel as Brian already mentioned (you can look that class up in the JavaDoc for your version of Tapestry).
On Tapestry 3 you have to add that feature to your model because LabeledPropertySelectionModel was introduced in version 4.
Upvotes: 2
Reputation: 13724
One solution is to use the LabeledPropertySelectionModel to wrap the real model like:
new LabeledPropertySelectionModel(new GenderModel(), "Choose an Option")
The JavaDoc for that class says:
Decorates an underlying IPropertySelectionModel adding an initial property. The label option, and value of the initial property are configurable.
Upvotes: 1