if you use new ChoiceRenderer(displayExpression) only then the id value (how we know what is selected) is the current index.
But in youre case it should be the id of the function
so i guess you have to have something like:

add(new DropDownChoice("function", functions, new ChoiceRenderer("name","id")).setRequired(true));

and id is also a property that returns the unique identifier of a function.

johan




On 3/20/06, Tom van Zummeren <[EMAIL PROTECTED]> wrote:

I have something I can't figure out about the DropDownChoice component.

 

This is the case:

 

I have a form, I have a CompoundPropertyModel attached to it to hold my domain object.

This domain object is already filled with data from the database, so I want this form to show the properties of the domain object (because this form is used for editing a database record).

In this case the domain object is an Employee. It has a firstName, a lastName and a function. First name and last name are Strings, but the function is a

Function object (also a domain object).

I was able to let the form show the firstName and lastName properties by using RequiredTextField like this:

 

add(new RequiredTextField("firstName", String.class));

add(new RequiredTextField("lastName", String.class));

 

But now for the function, I don't want to simply show the function name there. I want to have a dropdown box there, with all the functions from the database.

So I used the DropDownChoice component, I added it like this:

 

add(new DropDownChoice("function", functions, new ChoiceRenderer("name")).setRequired(true));

 

By the way, 'functions' is a LoadableDetachableModel which represents the complete list of functions of the database.

 

It all works fine, it shows the drop down list in the form with all the functions, but the problem is … it doesn't automatically select the right function from it's list!

 

So my question is: how can I let the DropDownChoice by default select the Function of the Employee I am editing?

 

(I hope I clearified my problem enough)

 

Thanks,

 

Tom

 


Reply via email to