This is an awkward way to do it, and still doesn't set the selected value back into his model.
The golden rule of DropDownChoice is: objects in the list must be of the same type as the model object. If you want your model to be updated with an int, you have to give DDC a list of Integer. The second rule is that you use a ChoiceRenderer to convert this value (the int) to a display value: class MyDomainClass { private int selection; } MyDomainClass myobj; add(new DropDownChoice("ddc", new PropertyModel(myobj, "selection"), Arrays.asList(1, 2, 3), new ChoiceRenderer() { public Object getDisplayValue(Object value) { // value is one of the objects from the list, // the one that the user selected Integer i = (Integer) value; // This function maps 1 to "abc" and so on... return getName(i); }) ); jk On Mon, Jul 27, 2009 at 12:36:39PM -0700, Mathias Nilsson wrote: > > class Choice{ > private int id; > private Stringvalue; > > // getters and setters > } > > List<Choice> choices = new LinkedList<Choice>(); > Choice c = new Choice(); > c.setId( 1 ); > c.setValue( "abc" ); > > choices.add( c ); > > // add the other values > > > // The choice with id 1 will be selected. > DropDownChoice drop = new DropDownChoice( "drop" , new Model( c ) , choices, > new ChoiceRenderer( "value" , "id" ) ); > > -- > View this message in context: > http://www.nabble.com/DropDownChoice-with-ID-and-Value-tp24686742p24686931.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org