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

Was it helpful?

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):

  1. Use a `PropertyModel. This is the cleanest of the three solutions, explained above.
  2. If input was constructed using a Model or PropertyModel you can call drop_down_status.getModelObject() then typecast the returned object back to the correct object type.
  3. Use an 'AjaxFormComponentUpdatingBehavior' to trigger an ad-hoc update when the object is modified.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top