anu
anu

Reputation: 59

how do i get values from wicket dropdown?

I am displaying dropdown, and that drop down having values like below.

What I want do is to get the id of selected value and pass to api but am not able to get id and value.can any one suggest me how to get value form dropdown.

     <select>
        <option value="" selected="selected">Choose One</option>
        <option value="id2">value2</option>
        <option value="id1">value1</option>
     </select>

My code is:

    final DropDownChoice<V> v1 = new DropDownChoice<V>("v1",
            new PropertyModel<V>(loc,"id"), getValueList(),
            new ChoiceRenderer<V>("name", "id"));

    v1.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (loc.getId() != null) {
                System.out.println("DDDDDDDD"+loc.getId());
                System.out.println("DDDDDDDD"+loc.getValue`enter code here`);
            }
        }
    });

Upvotes: 0

Views: 539

Answers (1)

tetsuo
tetsuo

Reputation: 10896

The value DropDownChoice will set in its model is not the id, but the chosen V itself. Thus, the IModel (in this case, the PropertyModel) should point to a property of type V.

Assuming loc is an attribute of this, try to replace

new PropertyModel<V>(loc, "id")

with

new PropertyModel<V>(this, "loc")

Upvotes: 2

Related Questions