Hello,
I have a web form where you can, generally speaking, assign objects to
groups. This is done via a multiple select box which displays an
object's name and uses its ID property as value.
So, usually, my action would get back a String array containing the IDs
of the selected objects. I want the framework to load the corresponding
objects from the database and pass them as a Collection to my action's
setObjects(Collection<Object> objects) method, so that my action doesn't
have to deal with loading objects.
So I wrote a type converter. The "convertFromString" method takes the
String array with the IDs, determines the target element type using
ObjectTypeDeterminer, loads the objects and returns them in a
collection. In this direction - form to action - it works quite well.
Now my questions:
1. extending StrutsTypeConverter forces me to implement String
convertToString(Map context, Object o). I think there is no common sense
way of converting a collection back to a String in this context. It
would, maybe, make sense to convert it to a String[]. But what I
actually want is to have access to the unconverted collection in the
JSP. This might seem strange from some point of view, and I could live
without it, but is there a way to do this? Example:
<s:select multiple="true"
name="myObjects"
list="myObjects" listKey="id" listValue="name" />
This way I could use getMyObjects() for displaying my objects and
setMyObjects() for setting them (using only their IDs).
2. Is there a way to define a type converter application wide, like
"always use this type converter for setting types which are subclasses
of X" and "for setting types which are Collection<subclass-of-X>"? This
way I could define the type converter once for all persistence-capable
classes.
Thanks in advance,
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]