File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts2 - Conversion problem for bi-dimensional Lists and Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 - Conversion problem for bi-dimensional Lists and Arrays" Watch "Struts2 - Conversion problem for bi-dimensional Lists and Arrays" New topic

Struts2 - Conversion problem for bi-dimensional Lists and Arrays

Ioan Damian Sirbu

Joined: Dec 22, 2008
Posts: 18
Good morning, this is a detailed follow up to a similar post I placed in the wrong section (sorry about that..).

I want to send a bidimensional List and/or a bidimensional array from my application's view to the action.

For example, I have a generixMatrix object in the action (with getters and setters of course). The genericMatrix should be able to hold any kind of object.
I want to set a 'Currency' object's 'value' field from the view, using an <input name="OGNL expression" value="theValue">
My problem is that i cannot address the Currency object properly with OGNL, or Struts does a bad type conversion.

I tried to represent a currencyMatrix that holds Currency objects
1) In the action:
List<List<Currency>> currencyMatrix
In the view:
None of these are working. I debugged and noticed that currencyMatrix gets initialized, but instead of RowDTO<Currency> elements, all its elements are null.

2) In the action
List<RowDTO<Currency>> currencyMatrix
where RowDTO<T> represents a row, having a field List<T> rowElements
In the view:
Same as above, currencyMatrix is filled with null elements

3)In the action:
List<currencyRowDTO> currencyMatrix
and RowDTO has a typed list List<Currency> currencyRowElements.
It works, but it does not help me. This forces me to create a new row object each time, like personRowDTO, anotherRowDTO etc.

Struts2 documentation specifies that "the Struts 2 type conversion mechanism can use generics-based typing to learn the correct target type for the conversions", but I think it defects when having nested generic types.

I also tried using a bidimensional array like Currency[][] but again I cannot find a way to reffer to it with OGNL.

I am open to any suggestions. To make a long story short, all I need is a sollution for a matrix-like object that can hold any type of object

Thank you in advance
I agree. Here's the link:
subject: Struts2 - Conversion problem for bi-dimensional Lists and Arrays
It's not a secret anymore!