OK, I've spent way too long trying to figure this out... :-/
I always get annoyed with having to play games in flowscript in order to use a selection list or a <fd:multivalue-field> to manipulate collections of beans. Those widgets work great for value types like String, not for entities. But that's another story... Today, I am trying to bind a repeater to a collection of String! And it's not working. Looking at the source code, I guess how I'm doing it isn't advertised to work in the first place... OK, fine, I just need to learn the correct way to accomplish it! :-)
So the deal is, the user gets to create new items or delete existing ones. (They don't get to change any existing items... just delete 'em. Hence the <fd:output>).
Here's my definition:
<fd:repeater id="editions">
<fd:label>Available Editions</fd:label>
<fd:widgets>
<fd:output id="name">
<fd:datatype base="string"/>
<fd:label>Name</fd:label>
</fd:output>
<fd:row-action id="delete" command="delete">
<fd:label>delete</fd:label>
</fd:row-action>
</fd:widgets>
</fd:repeater>
<fd:submit id="add-edition">
<fd:label>Add new</fd:label>
</fd:submit>
<fd:field id="new-edition-name">
<fd:datatype base="string"/>
<fd:validation>
<fd:length min="1">
<fd:failmessage>New edition must have a name</fd:failmessage>
</fd:length>
</fd:validation>
</fd:field>
And here's my binding:
<fb:repeater
id="editions"
parent-path="."
row-path="editions" <!-- a java.util.List -->
>
<fb:identity>
<fb:value id="name" path="." /> <!-- a java.lang.String -->
</fb:identity>
</fb:repeater>
The "Add new" button works by triggering this bit of flowscript:
form.lookupWidget ('editions')
.addRow()
.getChild('name').value =
form.lookupWidget ('new-edition-name').value;
...and the "delete" row-action just works... sorta (see below).
The "load" side works fine and the list displays correctly. The delete row-action appears to work fine (w.r.t. refreshing the page), and so does the scheme using the two widgets to add a new item. The problem is that when I do a save, the back end model isn't modified — the new items aren't added, and the deleted items aren't removed. So, two questions:
1) What is the deal with row deletion? Apparently when binding to an XML tree, you have to say
<fb:on-delete-row>
<fb:delete-node/>
</fb:on-delete-row>
if you want the delete row-action to do anything. Why? And don't you have to do anything special in the binding to make delete work when you are binding to a Collection? If so, what?
2) What's the deal with row insertion? I get this warning in the log
RepeaterJXPathBinding: RepeaterBinding has detected rows to insert, but misses the <on-insert-row> binding to do it.
OK, I get it... for a bean, we need to register a factory so that the binding will know how to create the new thing. Fair enough. But I've been looking at the documentation (http://cocoon.apache.org/2.1/userdocs/binding.html), and I don't get it... how about an example? And anyway, I don't have a bean here. Just a String. How do I make this work?
Thanks a lot!
—ml—
- [CForms] Howto?: bind repeater to collection of String Mark Lundquist
- Re: [CForms] Howto?: bind repeater to collection of St... Mark Lundquist
- Re: [CForms] Howto?: bind repeater to collection of St... Bruno Dumon
- Re: [CForms] Howto?: bind repeater to collection o... Mark Lundquist
- Re: [CForms] Howto?: bind repeater to collection of St... Simone Gianni
- Re: [CForms] Howto?: bind repeater to collection o... Mark Lundquist
- Re: [CForms] Howto?: bind repeater to collection o... Mark Lundquist
