This is wrong.

This is mentioned before on the list: The model object that is the selected object
should be the same kind of object that is in the choices (the list)

that is just a one-one mapping.

so if your list is:
final static List OPTIONS = Arrays.asList(new String[] {"Opt1", "Opt2", "Opt3"});

then

c.getMyOptionValue()

shoudl return one of those so Opt1, Opt2 or Opt3

if c can only return an int then the options list should just be a Integer array of those possible ints.
And the getDisplayValue should return Opt1 for integer1 and Opt2 for integer2 and so on.

Thats the idea.. The renderer gives you an method where you can return the display value of a real object.

johan



On 9/21/06, Dumitru Postoronca <[EMAIL PROTECTED]> wrote:
Hello everyone,

   I want to create an edit form and I'm trying to set the selected item
of a DropDownChoice to match what I have in the database.

The form constructor looks like this:
-----
public ClientEditPage(Client c) {...}
-----

The code that sets the form looks like this:

-----
final static List OPTIONS = Arrays.asList(new String[] {"Opt1", "Opt2",
"Opt3"});

//...

DropDownChoice ddc = new DropDownChoice(
        "options",
        new Model(c.getMyOptionValue()),
        OPTIONS,
        new ChoiceRenderer() {
                @Override
                public String getIdValue(Object arg0, int arg1) {
                // I also tried to return ((Integer)arg1).toString()
                // and it didn't work
                return ((Integer)OPTIONS.indexOf(arg0)).toString();
                }
        }
){      protected String getDefaultChoice(final Object selected)
{
        return ""; // remove "Choose One" prompt
}};

add(ddc);
-----

No matter what client I select, it always shows me the first option.
Also, the rendered HTML looks like this:
<option value="0">Opt1</option>
<option value="1">Opt2</option>
<option value="2">Opt3</option>

No selected="selected" attribute.

Can somebody tell me what am I doing wrong?

Thank you in advance,
- posto


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

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