struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Wieland <a.wiel...@syncapse.com>
Subject Specifying a custom type converter for a collection
Date Thu, 21 Jan 2010 23:45:55 GMT
I've read documentation that explains how to create a custom type converter, and how to apply
type conversion to a collection, but nothing that shows how to apply a custom type converter
to a collection. So far, none of my attempts have worked.

My action class has the following field, with the corresponding getter/setter:

   protected List<Device> selectedDevices;

There is a custom converter, DeviceStrutsTypeConverter, that has been used successfully to
convert a single instance of Device in other contexts. It takes a string ID and uses it to
load an instance of Device (an interface).

The view includes a select list with a name of "selectedDevices". The option values are IDs.

In the properties file for the action, I've added:

   Element_selectedDevices=my.package.Device
   CreateIfNull_selectedDevices=true

(I know that the name/path for the properties file is correct.)

I'm not sure how I'm supposed to associate the Device type with its converter. Device is an
interface, but that shouldn't matter if the converter is used to create instances. Adding
"selectedDevices=my.package.DeviceStrutsTypeConverter" doesn't make sense (or work) because
the converter doesn't apply to the collection as a whole. (Incidentally, I tried "selectedDevices=my.package.DeviceCollectionStrutsConverter",
after implementing a new converter that was designed to be applied directly to the collection,
but that didn't work either.) I tried adding "my.package.Device=my.package.DeviceStrutsConverter",
first to the properties file for the action, and then to xwork-conversion.properties (newly
created in the resources folder's root).

In all cases, selectedDevices remains stubbornly null or empty upon submitting my edits (it's
an edit action; the initial population of data and rendering work fine), and the breakpoint
in the converter is never reached. The request parameters map "selectedDevices" to an array
of string IDs, as expected.

All of which is a long-winded way of asking: How do you specify a custom type converter for
the elements of a collection? Any tips will be much appreciated.

Thanks,
Aaron

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