cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Portier <...@outerthought.org>
Subject Re: Woody, maps, and repeaters
Date Thu, 21 Aug 2003 10:33:26 GMT


Hugo Burm wrote:
> 
> I am trying to use the Woody sample that uses a Java bean for its binding
> (form2bean.flow).
> I want to store the contacts in this example in a map instead of in a list,

hm, the biggest problem I see with this 'storing in Map' is: 
"using which key?"

Maybe you should elaborate on your use case a bit. (Sorry, I 
still have to check up on your recent wiki page and accompanied 
zip.  In any case an upfront thx for sharing that!)

> but in this case the contacts are not displayed (one empty contact instead
> of 4), and submit gives an insert error for "contacts[1]).
> I had an almost identical problem with JXForms
> When I skip the Woody form in my flowscript, and just show the result page
> (form2_jx.xml), all my contacts are displayed OK. So JXPath knows how to
> iterate over a Map.

Could you show how your bean looks like?
And what is in it?

> I dived into the Woody sources and an obvious place to look is the Java
> class "RepeaterJXPathBinding.java" and especially the line
>         Iterator rowPointers =
> repeaterContext.iteratePointers(this.rowPath);

yep.

> in the function "loadFormFromModel" in this class.

this is for the binding from the bean to the form

as explained above the trouble I see is with binding back from 
the form to the bean (which key to use?)

> Can someone tell me whether this function iteratePointers() gives me the
> expected result: an iterator over the Map (this.rowPath)? I did check the
> JXPath docs and tried Google. I guess the answer is no, and because the
> iterator seems to have one value, I guess it returns one object with a list
> of keys and a list of values.
> 

I'm not completely sure what your trying to say here (or do in 
general) but there is afaik a difference in how jxpath looks to 
lists versus maps

LISTS
suppose myBean.getAddress returns a List then actually jxpath 
looks at your bean as if it would be an XML structure looking like
<myBean>
   <address><street/><city/></address>
   <address><street/><city/></address>
   <address><street/><city/></address>
</myBean>

leaving you with expressions like
$myBean/address[1]/street --> the street of the first address in 
the list, something equivalent to 
((Address)myBean.getAddress.get(0)).getStreet()

while $myBean/address --> iteration of the 3 address nodes


MAPS
suppose myBean.getAddress returns a Map with 3 keys say "hugo", 
"marc" and "bruno" then actually jxpath looks at your bean as if 
it would be an XML structure looking like
<myBean>
   <address>
     <hugo><street/><city/></hugo>
     <marc><street/><city/></marc>
     <bruno><street/><city/></bruno>
   </address>
</myBean>

leaving you with expressions like
$myBean/address[1]/street --> returning nothing
$myBean/address/hugo/street --> returning the street of the first 
address, ie equivalent to
((Address)myBean.getAddress.get("hugo")).getStreet()

and I'm not sure but probably
$myBean/* --> would give you the iteration of the 3 address nodes


in any case, I see some mismatches that would make the current 
RepaterBinding implementation not suitable for these Maps (since 
they are quite directed to the Lists, using the [index] notation 
and all)

however, if you can explain what sort of binding you would expect 
to be happening (in both bean and XML worlds) we can easily go 
for an extra MapRepeater binding or something...

regards,
-marc=
PS: a bit swamped, will do a best effort to follow up though
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


Mime
View raw message