Nishant Nawarkhede
Nishant Nawarkhede

Reputation: 8398

Wicket Framework DropDownChoice

I am trying to get selected value of dropdownchoice in wicket framework , but i am unable to get it. How can i get selected value of DropDownChoice on the change event of dropdownchoice ??? Thanks. I

Upvotes: 0

Views: 2621

Answers (2)

Javid Dadashkarimi
Javid Dadashkarimi

Reputation: 89

PropertyModel is good choice for such problems. MyObject is an object and has a string name.I have override the toString() method in it to name and it is working properly.I suggest using this method.

topicDropDown = new DropDownChoice<MyObject>("wicktID", new PropertyModel<MyObject>       (this.object, "exp"), new LoadableDetachableModel<List<MyObject>>() {
        @Override
        protected List<MyObject> load() {
            return top.getAllObjects();

        }

Upvotes: 2

Christoph Leiter
Christoph Leiter

Reputation: 9345

It's easy, all you have to do is use an AjaxFormComponentUpdatingBehavior:

DropDownChoice<String> ddc = new DropDownChoice<String>("ddc", model, Arrays.asList("a", "b", "c"));
ddc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    @Override
    protected void onUpdate(AjaxRequestTarget target) {
        System.out.println("selected: " + model.getObject());
    }
});

Upvotes: 7

Related Questions