struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Black <>
Subject Re: Type conversion of List<SomeInterface> - how does one do it?
Date Tue, 17 May 2011 21:42:37 GMT
Hey there Miguel.
Have a look here:

From: Miguel <>
Sent: Tuesday, May 17, 2011 5:19 AM
Subject: Type conversion of List<SomeInterface> - how does one do it?

I've always struggled with type conversion of lists and I'd appreciate a
more experienced brain to help me out.

Consider the following multiple select box:

<s:select     multiple="true" name="" list="users"     listKey="id"
listValue="username"    value="%{centre.users.{}}" />

As per the documentation, "name your element and the
framework will understand that it should create a new Person object for
each selected item and set its name accordingly."

This works correctly, without even needing an file if my action has:

private List<UserImpl> users;

However, because I usually work with interfaces (and Spring-inject my
dependencies), to have my action implementation-agnostic I want to have.

private List<User> users;

where User is an interface and UserImpl implements User.

However, as soon as the List (and getter/setters) are changed to use
User, the type conversion no longer works, yielding:

2011-05-17 11:17:13,554 WARN  [] : Error setting
expression '' with value '[Ljava.lang.String;@13d344e7'
ognl.OgnlException: Error converting given String values for Collection.
[org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'com.itclinical.iwrs.model.User': Could not resolve
matching constructor (hint: specify index/type/name arguments for simple
parameters to avoid type ambiguities)]

This happens even if I have a with:

So, how can one use the automatic type conversion when your list is
defined for an interface?

Thank you in advance,

Miguel Almeida
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message