I'm starting out with Wicket and following the Wicket In Action examples through and I'm a bit stuck on how to make use of a LoadableDetachableModel in a drop-down menu situation.

I've got a drop-down menu of countries which is populated from a LoadableDetachableModel, this works perfectly but my selected Country is then stored in the page as a complete object, I'd like to be able to make use of LoadableDetachableModel also for the selectedCountry but I'm not clear on where and how I should instantiate it. i.e. for the example below where do I put the "new LoadableRefDataModel<Country>(selectedCountry);".

I'd appreciate some suggestions, I think I'm getting the hang of the Model idea but can't see the wood for the trees at the moment.



public class LocationSearchPage extends WebPage {

    private DropDownChoice<Country> countryChoice;

    private DropDownChoice<Location> locationChoice;

    private Country selectedCountry;

    private List<Location> locations = new ArrayList<Location>();

    private Location selectedLocation;

    @SpringBean
    private RefDataService refDataService;

    public LocationSearchPage() {

        Form searchForm = new Form("searchForm") {
            @Override
            protected void onSubmit() {
                //...
            }
        };
        add(searchForm);

ChoiceRenderer countryRenderer = new ChoiceRenderer("description", "id"); IModel<List<? extends Country>> countryModel = new LoadableDetachableModel<List<? extends Country>>() {
            @Override
            protected List<Country> load() {
                return refDataService.getCountries();
            }
        };

        countryChoice = new DropDownChoice<Country>(
"country", selectedCountry, countryModel, countryRenderer);

countryChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            protected void onUpdate(AjaxRequestTarget target) {
                this.selectedLocation = null;
locationChoice.setChoices(new ArrayList<Country>(selectedCountry.getLocations()));
                target.addComponent(locationChoice);
            }
        });

ChoiceRenderer locationRenderer = new ChoiceRenderer("description", "id");
        locationChoice = new DropDownChoice<Location>(
"location", new PropertyModel<Location>(this, "selectedLocation"), locations, locationRenderer);
    }
}


public class LoadableRefDataModel<T extends RefData> extends LoadableDetachableModel {

    @SpringBean
    private RefDataService refDataService;

    private Class<T> type;

    private Serializable id;

    public LoadableRefDataModel(Class<T> type, Serializable id) {
        InjectorHolder.getInjector().inject(this);
        this.type = type;
        this.id = id;
    }

    public LoadableRefDataModel(T domainObject) {
        super(domainObject);
        InjectorHolder.getInjector().inject(this);
        this.type = (Class<T>) domainObject.getClass();
        this.id = domainObject.getCode();
    }

    @Override
    protected T load() {
        return refDataService.load(type, id);
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to