Hi,

You will need to implement and register a custom property editor for you
Directeur class which Spring will use to convert the class to and from
String form. To do this:

1) Create a class (I often do this as a nested class on the controller) that
extends PropertyEditorSupport. You will need to override the setAsText() and
getAsText() methods. Please be sure to include null value handling here.
2) Register your new class on your controller using the initBinder() method.

If you need more detail do a search for PropertyEditorSupport on the user
list in Nabble - something should pop up!

Answers to your other questions below:

On 7/25/07, Julien C. <[EMAIL PROTECTED]> wrote:

Hi,

I want to add a drop down list of user in a page (Spring MVC) :

so I implement the referenceData of my FormController :

@Override
@SuppressWarnings("unchecked")
protected Map referenceData(HttpServletRequest request) throws Exception {
log.debug("entering 'refenceData' function ..." );
// return super.referenceData(request);
Map model = new HashMap();
List<User> directeurs = getUserManager().getUsers(new User());
model.put( "directeurs", directeurs );
return model;
}

in my jsp :

<form:select path="directeur" itemValue="id" itemLabel="lastName"
items="${directeurs}"  ></form:select>

the data appears correctly on my page but when I save my form I've got
an error ( a other one;-) ) :

-----------------------
Failed to convert property value of type [java.lang.String] to required
type [org.appfuse.model.User] for property directeur; nested exception
is java.lang.IllegalArgumentException: Cannot convert value of type
[java.lang.String] to required type [org.appfuse.model.User] for
property directeur: no matching editors or conversion strategy found
-----------------------

I don't know how to correct the problem ( where and how do I make the
conversion ).
I have 2 small other questions :
- Is it possible to show in the list a label like surname + lastname ?


Yes - just implement a method on your class that returns the label in the
correct format and set the itemLabel attribute accordingly.

- I have seen a <s:select tag in my generated controller which come from
Struts (I think). Is there a reason . better than Spring select tag ?


Not sure on this one. The Spring tag is likely to work better with a Spring
controller due to binding paths.

Mike

Thank you. Julien C.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to