> Perhaps I don't understand the intended usage here.
> 
> It seems like the type of thing I want to do must be fairly 
> common.  Say I want to list US States by full name, but 
> persist the abbreviation (code) in my model.  A map of 
> Strings in the front end (display, value) to a String in the 
> model (value).  Is there a simple way to do this?
> 

Wicket's power comes from the fact that it works with objects and not ids.

USState modelObject=null; // this is where we want to persist the object

Model model=new Model(modelObject);

List<USState> states=getStatesList();

DropDownChoice choice=new DropDownChoice("state", model, states, new
ChoiceRenderer("code","name");

When the selection is made the modelObject will be populated with the
selected USState object.

If you want to persist just the code then your model needs to do the
conversion:

Here is some pseudo code:

Model model=new Imodel() {
        private String code;

        ongetobject() {

                // here we need to convert our string to an object

                return USState state=lookupstate(code);

        }

        onsetobject(Object obj) {

                // here we need to convert the usstate object back into code
string

                code=((USState)obj).getCode();

        }

}

List<USState> states=getStatesList();

DropDownChoice choice=new DropDownChoice("state", model, states, new
ChoiceRenderer("code","name");

Hope this makes sense
-Igor




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to