I've done some further debugging and here's what I now know:

1. I was able to bind TypeConverters to the model.group and
model.selectedNutrients properties by creating a
SimpleFoodCreationRequest-conversion.properties with the following lines:

group=com.opensymphony.xwork2.util.EnumTypeConverter
selectedNutrients=com.opensymphony.xwork2.util.EnumTypeConverter
Element_selectedNutrients=com.gb1.healthcheck.domain.nutrition.Nutrient

So converters can be defined at the nested object's level.

2. The group property is correctly mapped, the conversion being done by the
EnumTypeConverter.

3. The selectedNutrients property is still not being mapped correctly.  The
EnumTypeConverter is invoked to map the whole parameter array ([VITAMIN_A,
VITAMIN_B]) to an instance of Nutrient[].  To do this, it arbitrarly chooses
the first parameter (parameters[0] => VITAMIN_A) and tries to map it by
calling Enum.valueOf(Nutrient[].class, "VITAMIN_A").  This obviously fails.

Why doesn't Struts2 / XWork recognize that there are multiple parameters to
be mapped to multiple enums and call the EnumTypeConverter for each of them,
sending the resulting Nutrient[] to the request object?  Do I need to
specify something else?

Thanks,
GB


Guillaume Bilodeau wrote:
> 
> Hey no problem, I'm kind of sluggish also :)  It's true that I could use a
> different method name to expose the nested object, it does bring some
> confusion.
> 
> Somehow the group converter seems to work fine, so I don't understand why
> the nutrients doesn't. I'm knee-deep in OGNL code to see exactly what's
> going on now.
> 
> 
> newton.dave wrote:
>> 
>> Whoops!
>> 
>> Guillaume Bilodeau wrote:
>>> 1- I'm using "food.name" as the text field key - not
>>> as its name - so a localized label will be shown
>> next
>>> to it.
>> 
>> You're right; I didn't even see that.
>> 
>>> 2- I thought the action itself was pushed on the
>>> value stack and that one could reference and bind 
>>> parameters to nested objects in the JSP.
>> 
>> That is also correct; using the interface method name
>> threw me off (I probably wouldn't do that, although
>> there's no reason you can't).
>> 
>> *sigh* Gonna be one of those Mondays.
>> 
>> Does the "group" converter work properly?
>> 
>> d.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Mapping-multiple-enums-to-a-nested-object-tf4505238.html#a12883987
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to