I am not sure what the design decision was behind this and perhaps one of the Wicket Gurus can weigh in on this but I ran into something very similar recently, and here are my thoughts:
I think you are mixing the model object that backs the Dropdown and the actual Broker object. They are not the same thing. For example, having Broker id's in the final rendered HTML is a potential security risk. That being said, I could not find a elegant solution to the same exact problem. I ended up subclassing DropdownChoice. Adapted to your code, it looked something like: private HashMap<String, Broker>map = new HashMap<String, Broker>(); ... //get a list of the String that will be your choices for(Broker b : (Application) getApplication()).getBrokerDao().getUniqueBrokers()) { map.put(b.getName(), b); } setChoices(new ArrayList<String>(map.keySet())); ... public HashMap<String, Broker> getMap() { return map; } Then, in your onSubmit() method for the containing component you can access the Id of each broker like this: brokerDropDown.getMap().get(modelObject.getBrokerName()).getId() I hate this approach. I would love to have someone point me in a better direction. Yevgeni Kovelman wrote: > > I have the following problem, I have a dropdownchoice component. The load > method returns a list of Broker objects which have an id and displayName > attributes. Although currently not in this code, I will use the > iChoiceRenderer to populate the appropriate values. The Request instance > object is a backing object which contains brokerId as an attribute. > > > > My question is it possible to populate the instance.brokerId with the > broker > id that gets rendered by iChoiceRenderer. Currently I get an ClassCast > exception because the loaded model is of type Broker and the > instance.brokerId is long. > > > > Request instance = new Request(); > > // instance has broker as a long attribute > > > > Form form = new Form("entryForm", new CompoundPropertyModel(instance)); > > add(form); > > > > DropDownChoice broker = > > new DropDownChoice("broker", > > new PropertyModel(instance, "broker"), > > new LoadableDetachableModel() > > { > > @Override > > protected Object load() > > { > > return ((Application) getApplication()) > > .getBrokerDao().getUniqueBrokers(); > > } > > } > > ); > > broker.setRequired(true); > > form.add(broker); > > > -- View this message in context: http://www.nabble.com/dropdownchoice-tp14233301p14276903.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]