Wicket updates "selected_status" value "on the fly".
new PropertyModel<String>(this,"selected_status")
so its enough to get value from Model value :)
Question
so I have my DropDownChoice in Wicket:
final DropDownChoice drop_down_status = new DropDownChoice<String>("status", new PropertyModel<String>(this,"selected_status"), STATUS_LIST);
form.add(drop_down_status);
How to get the selected value? I have to get it after another button is pressed and prepare sql statement from it.
drop_down_status.getRawInput() and drop_down_status.getInput() return null ( at least in my case).
cheers
Solution 3
Wicket updates "selected_status" value "on the fly".
new PropertyModel<String>(this,"selected_status")
so its enough to get value from Model value :)
OTHER TIPS
Since you are constructing your DropDownChoice
using a PropertyModel
, the selection shown during initialization will correspond to the value of your selected_status
variable. When the drop_down_status
is changed, the propety model will update the selected_status
variable. So, you should be able to just look at that variable to see to see the current selection in the dropdown.
I have had frustration in the past getting the values from various inputs, but have found the following methods work fairly consistently (pick one):
Model
or PropertyModel
you can call drop_down_status.getModelObject()
then typecast the returned object back to the correct object type.example using AjaxFormComponentUpdatingBehavior:
drop_down_status.add(new AjaxFormComponentUpdatingBehavior("onChange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
selected_status = (Status) getFormComponent().getConvertedInput();
}
}
To reitterate what bert said above, models are the core of Wicket (i.e.- MVC=Model,View,Controller) and it helps tremendously to get familiar with their usage.
You pass a model to the DDC. In your case a property model. After a successful submit, the value is transferred to the model object 'selected_value'.
If you want to get anywhere with Wicket. Read up on the usage of models