Daniel Baldes wrote:
the problem here is that convertToString only allows returning .. a
String. Accessing "myObjects" in a JSP would always call
converter.convertToString(context, myaction.getMyObjects()) (as far as
I can tell). So this way I can't return a collection of objects where
I could, for example, iterate over.
Daniel
Ah, I see the problem better now. In your select:
<s:select multiple="true"
name="myObjects"
list="myObjects" listKey="id" listValue="name" />
you're trying to access myObjects as both a list of objects (list=) and
as a string (name=). You can't do what you're describing because
convertToString needs to provide the currently selected value for the
select.
I presume you don't really mean that, but rather want:
<s:select multiple="true"
name="mySelectedObject"
list="myObjects" listKey="id" listValue="name" />
where mySelectObject is the same class as the elements in the list, and
type conversion ensures that the select contains id:name and sees just
the selected object loaded from persistence and provides a list of
objects loaded from persistence (no handling of strings what-so-ever).
If I've misunderstood let me know.
Posting to your action:
When the params interceptor is invoked, it calls your custom converter
with the selected id value. Your converter looks up the entity in the
convertFromString method and returns the Object. The params interceptor
sets this object in your action. Perfect
Rendering the view:
The options in the select are populated by calls to convertToString on
each element in the list.
The currently selected value is also populated by a call to
convertToString on mySelectedObject
So, you definitely can't mix purposes here.
---
There has been talk on the developer list about providing a better model
for selects so your action doesn't have to provide the list of possible
values, and more importantly, the list of values is available after a
validation error without any further effort by your action. Nothing has
progressed AFAIK though.
Hope that was helpful and on track.
regards,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]