This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Struts2 - Conversion problem for bi-dimensional Lists and Arrays

Ioan Damian Sirbu
Greenhorn

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:
currencyMatrix[0][1].value
(currencyMatrix[0])[1].value
currencyMatrix.get(0).get(1)
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:
currencyMatrix[0].rowElements[1].value
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: http://aspose.com/file-tools
 
subject: Struts2 - Conversion problem for bi-dimensional Lists and Arrays
 
Similar Threads
Type conversion with an array in Struts2
Struts2/JQuery
struts2 + Json and JQuery.
Bidimensional array to GUI?
Passing bidimensional array/List from Velocity to Struts2