final LinkedHashMap preferences = new LinkedHashMap(); preferences.put("0", "some choice"); preferences.put("1", "some other choice"); preferences.put("2", "and another choice"); IModel dropDownModel = new Model() { public Object getObject() { return new ArrayList(preferences.keySet()); } };DropDownChoice profileChoice = new DropDownChoice("preference", dropDownModel, new IChoiceRenderer() {
public String getDisplayValue(Object object) { return preferences.get(object); } public String getIdValue(Object object, int index) { return object.toString(); } });I am using a CompoundPropertyModel for my form where the CPM has the property 'preference', so no need to explicitly tie the two together in the DDC.
Hopefully this will help others. cheers, Steve On 12 Dec 2008, at 18:39, Igor Vaynberg wrote:
that map needs to be in the choicerenderer. your domain model type is integer, ddc<integer> looks like this: dropdownchoice(string id, imodel<integer> model, imodel<list<integer>> choices, ichoicerenderer<integer> renderer) -igor On Fri, Dec 12, 2008 at 10:36 AM, Steve Swinsburg <s.swinsb...@lancaster.ac.uk> wrote:Thanks. I now have this: IModel dropDownModel = new Model() { protected Object load() { preferences.put(0, "some choice"); preferences.put(1, "some other choice"); preferences.put(2, "and another choice"); return preferences; //get the HashMap } };DropDownChoice profileChoice = new DropDownChoice("profile", dropDownModel,new IChoiceRenderer() { public String getDisplayValue(Object object) { return preferences.get(object); } public String getIdValue(Object object, int index) { return object.toString(); } });where my Form is given a CompoundPropertyModel with one of the parameters being "profile". But, I'm getting an error about my choices being null. java.lang.NullPointerException: List of choices is null - Was the supplied'Choices' model empty? I can feel I'm close but what have I missed? cheers, Steve On 12 Dec 2008, at 18:14, Igor Vaynberg wrote: new ichoicerenderer<integer>() { Object getDisplayValue(integer object) { return choices.get((integer)object); } String getIdValue(integer object, int index) { return object.tostring(); } } -igor On Fri, Dec 12, 2008 at 9:46 AM, Steve Swinsburg <s.swinsb...@lancaster.ac.uk> wrote: Hi all,I've been over all the DDC examples but am still stumped by this one. I havea model (pojo) which holds user preferences, the preference for each itembeing an Integer. ie public class UserPreferences { int preferenceOne; int preferenceTwo constructor getters and setters for the ints above }I now want to render a form that has a DDC for each of the preferences in mymodel. The list of choices that needs to go into the DDC should come from aHashMap or similar (in reality it will come from a database) because I wantto store the number attached to the item selected, not the display string.ie LinkedHashMap choices = new LinkedHashMap() choices.put("43", "Something"); choices.put("64", "Something else"); choices.put("87", "blah"); which should render the select list as: <select name="preferenceOne"> <option value="43">Choice Something</option> <option value="64">Choice Something else</option> <option value="87">blah</option> <select>When clicking submit, the value (ie 43) should be attached to the relevantitem in the Model (ie preferenceOne would be 43), then I can save it to thedatabase.Everything I've tried with ChoiceRenderer etc seems to get mixed up with thedifferent data models etc.Can someone please present a snippet of code on how to do this, I'm at mywits end. I cannot for the life of me find any explicit info separating themodels/data as above. thanks, Steve --------------------------------------------------------------------- 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
smime.p7s
Description: S/MIME cryptographic signature