views:

39

answers:

2

Hi,

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

+1  A: 

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();
    }
});
seanizer
A: 

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

virgium03