Greetings,

I am trying to take the value (only) of a DropDownChoice
and put it in a model set on the Form.

Ideally, I'd like to use a (java 5) enum, but any type of
name value pair will work.

For example, if I'm trying to set the size of a Shirt class, 
here is my Shirt, and a sample enum:


        public class Shirt
        {
                private int size;
                private int color;      
                //. . . 
                //(setters and getters removed to compact)
        }

        public static enum SIZE
        {
                Small("2"),
                Medium("4"),
                Large("6"),
                
                private String id;
                
                SIZE(String id)
                {
                        this.id = id;
                }
                
                public String getId()
                {
                        return id;
                }
                
                public String getName()
                {
                        return id + " - " + this.toString();
                }
        }

Now, in my Form, I set the shirt as a model.  When I add my "size"
DropDownChoice to the form, I am binding it to the size field of my
Shirt class:


        private class InputForm extends Form
        {
                public InputForm(String name)
                {
                        super(name, new CompoundPropertyModel(new Shirt()));    
                

                        DropDownChoice sizeChoice = new DropDownChoice("size",
                                Arrays.asList(SIZE.values()),                   
                
                                new ChoiceRenderer("name", "id"));

                        sizeChoice.setRequired(true);
                        add(sizeChoice);                
                        //. . .
                }
                
        }

When I submit this form, it fails because I get a "Small", "Medium", or
"Large"
object back.  What I want is the "id" of the selected object.
I looked at the examples in DropDownChoicePage.java in the compref package
of the
wicket examples and I could do that: create a list of Integers and use a
switch
or other technique to get the display value.

What I really want to do is bind the id property of the enum to the
Shirt.size property.
I've done this in reverse with a PropertyModel, binding a property of the
model to a field
on the page.  I having some trouble doing it this way.

I read through a number of the posts on DropDownChoice as a search item. 
None seem to hit the
nail on the head.  One poster mentioned using ChoiceRenderer, but I'm not
following how
that would work.

Any suggestions would be greatly appreciated!
I'm using Wicket 1.2.3 and java 5 in Tomcat.

-- 
View this message in context: 
http://www.nabble.com/DropDownChoice-binding-question-tf2900580.html#a8103832
Sent from the Wicket - User mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to