I'm sorry, I don't think I quite understand.

I have dropDownModel which looks like this:

            IModel dropDownModel = new Model()
            {
                protected Object load()
                {
                    return StringValues.getUSAStates(); //via proxy
                }
            };

StringValues.getUSAStates() looks something like this:

    public static Map<String, String> getUSAStates()
    {
        Map<String, String> states = new HashMap<String, String>();
        states.put("AL", "Alabama");
        states.put("AK", "Alaska");
        states.put("AZ", "Arizona");
        states.put("AR", "Arkansas");
        states.put("CA", "California");
......

Where "CA" is the key and "California" is the value...which is exactly how I'd like to see it in the select dropdown.

Are you saying that I should split the keys and values into two different lists and look them up that way?

It would be extremely useful, in my opinion, if Wicket had support for these types of objects internally, given the frequency of which they're used.  It would be very intuitive if I could supply key/value Map objects into what is essentially a list of key/value pairs.

Thanks again...

On 4/10/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
give the choice renderen the complete hashmap

And give the dropdown a model with the keys of that hashmap as a list.

so if StringValues.getUSAStates(); are th ids in the hashmap then that should go ok.

but youre choicerender is wrong:


  add(new DropDownChoice("billingState", dropDownModel, new IChoiceRenderer()
            {
                public String getDisplayValue(Object object)
                {
                    return idValueHashmap.get(object);

                }
               
                public String getIdValue(Object object, int index)
                {
                    return object.toString();
                }
            }));

On 4/11/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:
Is there an example of this somewhere?  I'm struggling to get this working where I have a HashMap<String, String>...the first String is the ID and the second String is the value.

I have this:
            IModel dropDownModel = new Model()
            {
                protected Object load()
                {
                    return StringValues.getUSAStates();
                }
            };

            add(new DropDownChoice("billingState", dropDownModel, new IChoiceRenderer()
            {
                public String getDisplayValue(Object object)
                {
                    return object.toString();
                }
               
                public String getIdValue(Object object, int index)
                {
                    return object.toString();
                }
            }));

I *just* wanted to see the page render...I know the values aren't right...but anything would have been acceptable.  I keep getting a very unhelpful NullPointerException that I'm not even sure has anything to do w/ the dropdowns...but I assume it does since the rest of the form is very straightforward TextField components.

I don't see where this is being done in wicket-examples....I'm using 1.1.1

Thanks!

On 4/1/06, Johan Compagner < [EMAIL PROTECTED]> wrote:
there is no map support for this.

What you could do is give the map to the ChoiceRenderer impl
and give the keys of the map as a list to the Choice.

johan



On 3/31/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:
I'm trying to get a Map of data so I can have the key be the value of the dropdown options and the value of the Map item be the value of the option in the dropdown.  Problem is, it doesn't look like DropDownChoice will accept a Map...unless I'm doing it wrong?

Is a Map the best way to go?  I was maybe considering using a single List collection and splitting a single string to get the two values....but that's pretty fugly too.




Reply via email to