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 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:

<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 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


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to