Re: DropDownChoice with Model for data and HashMap of key/values
Oh yeah I didn't mean the admins if that what you were referring to in the '5 of us', I just thought maybe more of a community input, like other development mailing lists I'm a part of. But anyway, solution found! cheers, Steve On 15 Dec 2008, at 15:49, Igor Vaynberg wrote: On Mon, Dec 15, 2008 at 6:02 AM, Steve Swinsburg wrote: After a fresh start on a Monday, I figured out how to use a Hashmap in a DropDownChoice component when separate id/display values are required. I was hoping to get a bit more of an explicit answer from the community on this one though, since I was completely stumped, which is what I thought this mailing list was for. keep in mind that there are 5 of us and 400 of you. i believe i gave you more then enough of a push in the right direction to solve the problem. and looks like you did. -igor Anyway, its solved: 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 looks like this: dropdownchoice(string id, imodel model, imodel> choices, ichoicerenderer renderer) -igor On Fri, Dec 12, 2008 at 10:36 AM, Steve Swinsburg 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() { 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 wrote: Hi all, I've been over all the DDC examples but am still stumped by this one. I have a model (pojo) which holds user preferences, the preference for each item being 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 my model. The list of choices that needs to go into the DDC should come from a HashMap or similar (in reality it will come from a database) because I want to 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: Choice Something Choice Something else blah When clicking submit, the value (ie 43) should be attached to the relevant item in the Model (ie preferenceOne would be 43), then I can save it to the database. Everything I've tried with ChoiceRenderer etc seems to get mixed up with the different data models etc. Can someone please present a snippet of code on how to do this, I'm at my wits end. I cannot for the life of me find any explicit info separating the models/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 - To unsubscribe, e-mail: users-unsubscr...@wicket.
Re: DropDownChoice with Model for data and HashMap of key/values
On Mon, Dec 15, 2008 at 6:02 AM, Steve Swinsburg wrote: > After a fresh start on a Monday, I figured out how to use a Hashmap in a > DropDownChoice component when separate id/display values are required. I was > hoping to get a bit more of an explicit answer from the community on this > one though, since I was completely stumped, which is what I thought this > mailing list was for. keep in mind that there are 5 of us and 400 of you. i believe i gave you more then enough of a push in the right direction to solve the problem. and looks like you did. -igor > Anyway, its solved: > > 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 looks like this: > > dropdownchoice(string id, imodel model, imodel> > choices, ichoicerenderer renderer) > > -igor > > On Fri, Dec 12, 2008 at 10:36 AM, Steve Swinsburg > 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() { > > 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 > > wrote: > > Hi all, > > I've been over all the DDC examples but am still stumped by this one. I have > > a model (pojo) which holds user preferences, the preference for each item > > being 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 my > > model. The list of choices that needs to go into the DDC should come from a > > HashMap or similar (in reality it will come from a database) because I want > > to 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: > > > > Choice Something > > Choice Something else > > blah > > > > When clicking submit, the value (ie 43) should be attached to the relevant > > item in the Model (ie preferenceOne would be 43), then I can save it to the > > database. > > Everything I've tried with ChoiceRenderer etc seems to get mixed up with the > > different data models etc. > > Can someone please present a snippet of code on how to do this, I'm at my > > wits end. I cannot for the life of me find any explicit info separating the > > models/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 > > > - To unsubscribe, e-mail: users-unsubscr...
Re: DropDownChoice with Model for data and HashMap of key/values
After a fresh start on a Monday, I figured out how to use a Hashmap in a DropDownChoice component when separate id/display values are required. I was hoping to get a bit more of an explicit answer from the community on this one though, since I was completely stumped, which is what I thought this mailing list was for. Anyway, its solved: 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 looks like this: dropdownchoice(string id, imodel model, imodel> choices, ichoicerenderer renderer) -igor On Fri, Dec 12, 2008 at 10:36 AM, Steve Swinsburg 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() { 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 wrote: Hi all, I've been over all the DDC examples but am still stumped by this one. I have a model (pojo) which holds user preferences, the preference for each item being 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 my model. The list of choices that needs to go into the DDC should come from a HashMap or similar (in reality it will come from a database) because I want to 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: Choice Something Choice Something else blah When clicking submit, the value (ie 43) should be attached to the relevant item in the Model (ie preferenceOne would be 43), then I can save it to the database. Everything I've tried with ChoiceRenderer etc seems to get mixed up with the different data models etc. Can someone please present a snippet of code on how to do this, I'm at my wits end. I cannot for the life of me find any explicit info separating the models/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
Re: DropDownChoice with Model for data and HashMap of key/values
that map needs to be in the choicerenderer. your domain model type is integer, ddc looks like this: dropdownchoice(string id, imodel model, imodel> choices, ichoicerenderer renderer) -igor On Fri, Dec 12, 2008 at 10:36 AM, Steve Swinsburg 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() { > 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 > wrote: > > Hi all, > > I've been over all the DDC examples but am still stumped by this one. I have > > a model (pojo) which holds user preferences, the preference for each item > > being 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 my > > model. The list of choices that needs to go into the DDC should come from a > > HashMap or similar (in reality it will come from a database) because I want > > to 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: > > > > Choice Something > > Choice Something else > > blah > > > > When clicking submit, the value (ie 43) should be attached to the relevant > > item in the Model (ie preferenceOne would be 43), then I can save it to the > > database. > > Everything I've tried with ChoiceRenderer etc seems to get mixed up with the > > different data models etc. > > Can someone please present a snippet of code on how to do this, I'm at my > > wits end. I cannot for the life of me find any explicit info separating the > > models/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
Re: DropDownChoice with Model for data and HashMap of key/values
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() { 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 wrote: Hi all, I've been over all the DDC examples but am still stumped by this one. I have a model (pojo) which holds user preferences, the preference for each item being 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 my model. The list of choices that needs to go into the DDC should come from a HashMap or similar (in reality it will come from a database) because I want to 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: Choice Something Choice Something else blah When clicking submit, the value (ie 43) should be attached to the relevant item in the Model (ie preferenceOne would be 43), then I can save it to the database. Everything I've tried with ChoiceRenderer etc seems to get mixed up with the different data models etc. Can someone please present a snippet of code on how to do this, I'm at my wits end. I cannot for the life of me find any explicit info separating the models/data as above. thanks, Steve - 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
Re: DropDownChoice with Model for data and HashMap of key/values
new ichoicerenderer() { 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 wrote: > > Hi all, > > I've been over all the DDC examples but am still stumped by this one. I have > a model (pojo) which holds user preferences, the preference for each item > being 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 my > model. The list of choices that needs to go into the DDC should come from a > HashMap or similar (in reality it will come from a database) because I want > to 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: > > > Choice Something > Choice Something else > blah > > > When clicking submit, the value (ie 43) should be attached to the relevant > item in the Model (ie preferenceOne would be 43), then I can save it to the > database. > > Everything I've tried with ChoiceRenderer etc seems to get mixed up with the > different data models etc. > > Can someone please present a snippet of code on how to do this, I'm at my > wits end. I cannot for the life of me find any explicit info separating the > models/data as above. > > > > thanks, > Steve > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org