You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Maxx <ma...@gmail.com> on 2008/02/27 13:00:14 UTC
Nested Map & List type conversion properties settings
Hello,
Working on it for a while but couldn't find a solution. In my action I
need the following Map:
Map<String, List<MyBean>> myList;
... where the class MyBean is something like:
class MyBean {
private Long id;
private String name;
// + appropriate getters/setters
}
What I'd like is setting each value back through some <s:textfield />
using the particular OGNL as described here:
http://struts.apache.org/2.x/docs/type-conversion.html
For generating all the appropriate <s:textfield /> I have two nested
iterators; first one for the Map, second one for the List. But how do
I do with my OGNL expressions to be put in the value="" attribute of
the text fields.
I'm guessing it's something like:
myList['mapKey'](beanId)
but I could not find how to configure it properly because it seems
there's a conflict between how to declare the Map conversion & how to
declare the pseudo-collection index for a single myList[...] value
# conf. for the Map
Key_myList=String
Element_myList=java.util.Map
CreateIfNull_myList=true
# conf. for the Map...??? how to indicate here it's a value in the
map, not the map itself!!?
KeyProperty_myList=id
Element_myList=com.mycompany.somepackage.www.bean.MyBean
CreateIfNull_myList=true
Thanks for your help!
Maxx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Nested Map & List type conversion properties settings
Posted by Dave Newton <ne...@yahoo.com>.
--- Maxx <ma...@gmail.com> wrote:
> Map<String, List<MyBean>> myList;
>
> ... where the class MyBean is something like:
>
> class MyBean {
> private Long id;
> private String name;
> // + appropriate getters/setters
> }
>
> What I'd like is setting each value back through some <s:textfield />
> using the particular OGNL as described here:
> http://struts.apache.org/2.x/docs/type-conversion.html
> For generating all the appropriate <s:textfield /> I have two nested
> iterators; first one for the Map, second one for the List. But how do
> I do with my OGNL expressions to be put in the value="" attribute of
> the text fields.
>
> I'm guessing it's something like:
> myList['mapKey'](beanId)
> but I could not find how to configure it properly because it seems
> there's a conflict between how to declare the Map conversion & how to
> declare the pseudo-collection index for a single myList[...] value
>
> # conf. for the Map
> Key_myList=String
> Element_myList=java.util.Map
> CreateIfNull_myList=true
>
> # conf. for the Map...??? how to indicate here it's a value in the
> map, not the map itself!!?
> KeyProperty_myList=id
> Element_myList=com.mycompany.somepackage.www.bean.MyBean
> CreateIfNull_myList=true
AFAIK until you can name it you can't reference it: if you have a map with an
"anonymous" value there's no way to describe to the system how to handle it.
For example, my first S2 app had a fairly deeply nested structure for which
the textfields looked similar to this:
<s:textfield name="aMap[%{#result.id}].%{which}[0].foo" .../>
Here the value of "which" names a list (the index is hard-coded here to keep
it simple), which is a member of the object held in the map with an ID-like
index.
The conversion file (more or less, and I'm not even sure all of it is
necessary) looks like this:
Key_aMap=java.lang.Long
Element_aMap=foo.bar.Baz
CreateIfNull_aMap=true
# Here I was just checking "Collection" v. "Element"--this was a long time
ago.
# In the textfield above "%{which}" would be replaced by the string "aThing"
or "anotherThing".
Collection_aThing=com.over.wtf.DataType
Element_anotherThing=com.over.wtf.DataType
I'm not sure the automagic generics support follows the entire chain of
definitions; if you don't have a conversion file at all you'll probably end
up with an exception setting the MyBean values with a String[].
(Caveat: this got edited over a longer period of time than I originally
anticipated so may not be totally coherent, but that's par for the course for
me.)
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org