Nitesh Sharma
Nitesh Sharma

Reputation: 11

Getting value of selected option from drop down in Apache wicket

I want to retreive the value of selected option from a DropdownChoice on click of Link in Apache Wicket.This works on click of button but not on click of Link.

Please guide.

Thanks, Nitesh

Upvotes: 1

Views: 1645

Answers (2)

virgium03
virgium03

Reputation: 637

You need to have a SubmitLink or an AjaxSubmitLink, and thus the selected DropDownChoice value will be given by its model.

Upvotes: 0

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298818

Well the difference between a button and a link is that a button submits a Form while a Link doesn't. So for a Link there is usually no way to know what the form value is. However, there is a solution here for you:

AjaxSubmitLink is a Link that submits a Form when the link is clicked, and hence supports the functionality you are talking about. However, this is a component that works with JavaScript only. Here's how you'd call it if your Form's model object is of type Thingy:

add(new AjaxSubmitLink(id, form){

    private static final long serialVersionUID = 1L;

    @Override
    protected void onSubmit(final AjaxRequestTarget target,
        final Form<?> form){
        String selectedValue = ((Thingy) form.getModelObject()).getFooProperty();
    }
});

Upvotes: 1

Related Questions