cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christofer Dutz <d...@c-ware.de>
Subject Re: CForm repeater binding problem
Date Tue, 31 May 2005 21:09:49 GMT
Ok ... this starts geting sort of a habit, but I think I might just post
my results here. Mabe they will help someone.

In my case I used an ordinary repeater for bining the repeater to my
xml-document. I don't know why, but it seems that updates aren't relayed
to the xml-document automatically.
I had to create a function which is called upon each change of a value.
In this function I simply update my document menually. This worked fine
for me. The downside was that I had to
deal with the "move-up" and "move-down" stuff on my own, wich was sort
of not what I wanted.

On my search I stumbled over the "fb:simple-repeater" binding. After
changing the binding posted below to the folowing everything was
perfect. Sometimes the easy was is the best.
I think I chose the complicated repeater because of the "A simple
repeater binding that will replace (i.e. delete then re-add all) its
content." comment sounded sort of bad.

<?xml version="1.0" encoding="UTF-8"?>
<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
path="/cart/cartContent">
    <fb:simple-repeater id="cartContent" parent-path="content"
row-path="product">
        <fb:value id="count" path="@count"/>
        <fb:value id="product" path="@product"/>
        <fb:value id="productNo" path="@productNo"/>
        <fb:value id="price" path="@price"/>
        <fb:value id="totalPrice" path="@totalPrice"/>
    </fb:simple-repeater>
</fb:context>

Christofer Dutz wrote:

> Hi,
>
> I am still having problems with repeaters. I have created a small
> shoping-cart form which contains a repeater. Every cart wow contains
> several output-widgets, one textfield (used for editing the number of
> products) and now some row-actions for deleting and mooving up and down
> items. I added these for testing since they initiate a submit and
> redisplay of a reult page without returning to the flowscript.
> This way I could test if it's a binding-problem or a forms-problem.
> I am able to update the cart-elements count, delete items and move them
> up and down so I guess, that principly everything should be fine. If I
> hit the "Next" or "Update" Button control is returned to the Flowscript
> and the xml-document sotring the carts content ist updated. If I output
> the xml-document (simple Stdout to my Jboss-Logfile) no changes were
> made. Could you please give me a hint to where my problem is? Here the 
> code:
>
> Bindng:
> <?xml version="1.0" encoding="UTF-8"?>
> <fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
> path="/cart/cartContent">
>    <fb:repeater id="cartContent" parent-path="content" 
> row-path="product">
>        <fb:identity id="productNo" path="@productNo"/>
>        <fb:on-bind>
>            <fb:value id="count" path="@count"/>
>            <fb:value id="product" path="@product"/>
>            <fb:value id="productNo" path="@productNo"/>
>            <fb:value id="price" path="@price"/>
>            <fb:value id="totalPrice" path="@totalPrice"/>
>        </fb:on-bind>
>    </fb:repeater>
> </fb:context>
>
> Form:
> <fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
>    <fd:widgets>
>        <fd:repeater id="cartContent" initial-size="0">
>            <fd:label>Warenkorb:</fd:label>
>            <fd:widgets>
>                <fd:field id="count" requried="true">
>                    <fd:label>Anzahl:</fd:label>
>                    <fd:datatype base="string"/>
>                </fd:field>
>                <fd:row-action id="deleteItem" action-command="delete">
>                    <fd:label>Produkt aus Warenkorb entfernen</fd:label>
>                </fd:row-action>
>                <fd:row-action id="itemUp" action-command="move-up">
>                    <fd:label>Produkt nach oben bewegen</fd:label>
>                </fd:row-action>
>                <fd:row-action id="itemDown" action-command="move-down">
>                    <fd:label>Produkt nach unten bewegen</fd:label>
>                </fd:row-action>
>                <fd:output id="product">
>                    <fd:label>Artikel:</fd:label>
>                    <fd:datatype base="string"/>
>                </fd:output>
>                <fd:output id="productNo">
>                    <fd:label>Bestellnummer:</fd:label>
>                    <fd:datatype base="string"/>
>                </fd:output>
>                <fd:output id="price">
>                    <fd:label>Einzelpreis:</fd:label>
>                    <fd:datatype base="string"/>
>                </fd:output>
>                <fd:output id="totalPrice">
>                    <fd:label>Gesamtpreis:</fd:label>
>                    <fd:datatype base="string"/>
>                </fd:output>
>            </fd:widgets>
>        </fd:repeater>
>        <fd:submit id="updateButton" validate="true">
>            <fd:label>Aktualisieren</fd:label>
>        </fd:submit>
>        <fd:submit id="nextButton" validate="true">
>            <fd:label>Weiter</fd:label>
>        </fd:submit>
>    </fd:widgets>
> </fd:form>
>
> Template:
> <page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
> xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">
>    <title>Warenkorb</title>
>    <include src="/shop/utils/forms-lib.js"/>
>    <paragraph style="width:990px;height:445px">
>        <ft:form-template action="#{$continuation/id}.continue"
> method="POST">
>            <paragraph style="width:990px;height:385px">
>                <br/>
>                <paragraph
> style="width:18px;height:25px;float:left;border:none;">
>                    <image url="/images/popup-button-left.gif"/>
>                </paragraph>
>                <paragraph
> style="width:140px;height:25px;float:left;border:none;background-color:rgb(60,70,131);text-align:left;">

>
>                    <ft:repeater-widget-label id="cartContent"
> widget-id="count"/>
>                </paragraph>
>                <paragraph
> style="width:410px;height:25px;float:left;border:none;background-color:rgb(60,70,131);text-align:left;">

>
>                    <ft:repeater-widget-label id="cartContent"
> widget-id="product"/>
>                </paragraph>
>                <paragraph
> style="width:200px;height:25px;float:left;border:none;background-color:rgb(60,70,131);text-align:left;">

>
>                    <ft:repeater-widget-label id="cartContent"
> widget-id="productNo"/>
>                </paragraph>
>                <paragraph
> style="width:100px;height:25px;float:left;border:none;background-color:rgb(60,70,131);text-align:left;">

>
>                    <ft:repeater-widget-label id="cartContent"
> widget-id="price"/>
>                </paragraph>
>                <paragraph
> style="width:100px;height:25px;float:left;border:none;background-color:rgb(60,70,131);text-align:left;">

>
>                    <ft:repeater-widget-label id="cartContent"
> widget-id="totalPrice"/>
>                </paragraph>
>                <paragraph
> style="width:18px;height:25px;float:left;border:none;">
>                    <image url="/images/popup-button-right.gif"/>
>                </paragraph>
>                <ft:repeater-widget id="cartContent">
>                    <paragraph style="width:990px;height:25px">
>                        <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                        <paragraph
> style="width:140px;height:25px;float:left;border:none;text-align:left;">
>                            <ft:widget id="count">
>                                <fi:styling style="width:60px"/>
>                            </ft:widget>
>                            <ft:widget id="deleteItem">
>                                <fi:styling type="image"
> src="/images/delete.gif"/>
>                            </ft:widget>
>                            <ft:widget id="itemUp">
>                                <fi:styling type="image"
> src="/images/up.gif"/>
>                            </ft:widget>
>                            <ft:widget id="itemDown">
>                                <fi:styling type="image"
> src="/images/down.gif"/>
>                            </ft:widget>
>                        </paragraph>
>                        <paragraph
> style="width:410px;height:25px;float:left;border:none;text-align:left;">
>                            <ft:widget id="product"/>
>                        </paragraph>
>                        <paragraph
> style="width:200px;height:25px;float:left;border:none;text-align:left;">
>                            <ft:widget id="productNo"/>
>                        </paragraph>
>                        <paragraph
> style="width:100px;height:25px;float:left;border:none;text-align:left;">
>                            <ft:widget id="price"/>
>                        </paragraph>
>                        <paragraph
> style="width:100px;height:25px;float:left;border:none;text-align:left;">
>                            <ft:widget id="totalPrice"/>
>                        </paragraph>
>                        <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                    </paragraph>
>                </ft:repeater-widget>
>                <br/>
>                <paragraph style="width:990px;height:25px">
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                    <paragraph
> style="width:850px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:left;">Gesamt

>
> Bestellwert:</paragraph>
>                    <paragraph
> style="width:100px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:right;">orderValue</paragraph>

>
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                </paragraph>
>                <br/>
>                <paragraph style="width:990px;height:25px">
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                    <paragraph
> style="width:850px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:left;">Porto

>
> &amp; Verpackung  (frei ab 100,00 Bestellwert):</paragraph>
>                    <paragraph
> style="width:100px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:right;">0.00</paragraph>

>
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                </paragraph>
>                <br/>
>                <paragraph style="width:990px;height:25px">
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                    <paragraph
> style="width:850px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:left;">Gesamtpreis:</paragraph>

>
>                    <paragraph
> style="width:100px;height:25px;float:left;border-top-width:1px;border-top-style:solid;border-color:#CCCC99;text-align:right;">0.00</paragraph>

>
>                    <paragraph
> style="width:18px;height:25px;float:left;border:none;"/>
>                </paragraph>
>            </paragraph>
>            <paragraph style="width:570px;height:35px;margin-left:420px">
>                <table style="width:570px;empty-cells:show">
>                    <row>
>                        <cell style="width:190px;tex-align:center">
>                            <ft:widget id="updateButton">
>                                <fi:styling type="image"
> src="/images/buttons/Aktualisieren.png"/>
>                            </ft:widget>
>                        </cell>
>                        <cell style="width:190px;tex-align:center">
>                    </cell>
>                        <cell style="width:190px;tex-align:center">
>                            <ft:widget id="nextButton">
>                                <fi:styling type="image"
> src="/images/buttons/Weiter.png"/>
>                            </ft:widget>
>                        </cell>
>                    </row>
>                </table>
>            </paragraph>
>        </ft:form-template>
>    </paragraph>
> </page>
>
> Flowscruipt:
> importClass(javax.xml.parsers.DocumentBuilderFactory);
> importClass(org.apache.xpath.XPathAPI);
> importClass(org.apache.xpath.XPathAPI);
> importClass(org.w3c.dom.Document);
> importClass(org.w3c.dom.Node);
> importClass(org.w3c.dom.Element);
> importClass(org.w3c.dom.NodeList);
>
> importClass(org.apache.xml.serialize.XMLSerializer);
> importClass(java.io.StringWriter);
>
> // load CForms support
> cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js"); 
>
>
> var cart = null;
>
> function getCart() {
>    if(cart == null) {
>        this.cart =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
>        var cartRoot = this.cart.createElement("cart");
>        this.cart.appendChild(cartRoot);
>
>        var cartContent = this.cart.createElement("cartContent");
>        cartRoot.appendChild(cartContent);
>        var cartContentContent = this.cart.createElement("content");
>        cartContent.appendChild(cartContentContent);
>        var billingAddress = this.cart.createElement("billingAddress");
>        cartRoot.appendChild(billingAddress);
>        var shippingAddress = this.cart.createElement("shippingAddress");
>        cartRoot.appendChild(shippingAddress);
>
>        // For debugging purposes
>        var product =  this.cart.createElement("product");
>        cartContentContent.appendChild(product);
>        product.setAttribute("productNo", "ABC");
>        product.setAttribute("product", "Testprodukt");
>        product.setAttribute("count", "5");
>        product.setAttribute("price", "42.23");
>        product.setAttribute("totalPrice", "211.15");
>
>        var product2 =  this.cart.createElement("product");
>        cartContentContent.appendChild(product2);
>        product2.setAttribute("productNo", "ABCD");
>        product2.setAttribute("product", "Testprodudfggkt");
>        product2.setAttribute("count", "8");
>        product2.setAttribute("price", "424.23");
>        product2.setAttribute("totalPrice", "2141.15");
>
>        print("created new cart document");
>    }
>    return cart;
> }
>
> function printCart() {
>    var serializer = new XMLSerializer();
>    var writer = new StringWriter();
>    serializer.setOutputCharStream(writer);
>    serializer.serialize(cart);
>    print(writer.toString());
> }
>
> /*
>    Function for dealing with the shoping cart itself. It herby has to
>    deal with updating the carts content, removing products from the
>    cart and doin the order processing
> */
> function showCart() {
>    print("showCart");
>    getCart();
>
>    // Initialize the forms and create their corresponding bindings.
>    var cartForm = new Form("shop/forms/shoppingCartForm.xml");
>    cartForm.createBinding("shop/bindings/shoppingCartBinding.xml");
>    var addressForm = new Form("shop/forms/billingAddressForm.xml");
>    addressForm.createBinding("shop/bindings/billingAddressBinding.xml");
>    var shippingForm = new Form("shop/forms/shippingAddressForm.xml");
>    
> shippingForm.createBinding("shop/bindings/shippingAddressBinding.xml");
>    var summaryForm = new Form("shop/forms/summaryForm.xml");
>    summaryForm.createBinding("shop/bindings/summaryBinding.xml");
>
>    // Initialize the variables for locally tracking the users state.
>    var local = cocoon.createPageLocal();
>    local.loop = true;
>    local.state = 1;
>    while(local.loop) {
>        printCart();
>        switch(local.state) {
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            // Send the cart form
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            case 1: {
>                cartForm.load(cart);
>                cartForm.showForm("shop/shoppingCartTemplate.jexl");
>                cartForm.save(cart);
>                if(cartForm.submitId == "nextButton") {
>                    local.state = 2;
>                }
>                break;
>            }
>
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            // Send the address form
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            case 2: {
>                addressForm.load(cart);
>                addressForm.showForm("shop/billingAddressTemplate.jexl");
>                addressForm.save(cart);
>                // Depending on if an alternate shipping-address should
>                // be entered, go to the shipping-address-page or directly
>                // proceed to the confirmation-page.
>                if(addressForm.submitId == "prevButton") {
>                    local.state = 1;
>                } else if(addressForm.submitId == "nextButton") {
>
> if(addressForm.lookupWidget("/differentShippingAddress").getValue() ==
> "true") {
>                        local.state = 3;
>                    } else {
>                        local.state = 4;
>                    }
>                }
>                break;
>            }
>
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            // Send the shipping form
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            case 3: {
>                shippingForm.load(cart);
>                
> shippingForm.showForm("shop/shippingAddressTemplate.jexl");
>                shippingForm.save(cart);
>                if(shippingForm.submitId == "prevButton") {
>                    local.state = 2;
>                } else if(shippingForm.submitId == "nextButton") {
>                    local.state = 4;
>                }
>                break;
>            }
>
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            // Send the summary form
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            case 4: {
>                summaryForm.load(cart);
>                summaryForm.showForm("shop/summaryTemplate.jexl");
>                if(summaryForm.submitId == "prevButton") {
>
> if(addressForm.lookupWidget("/differentShippingAddress").getValue() ==
> "true") {
>                        local.state = 3;
>                    } else {
>                        local.state = 2;
>                    }
>                } else if(summaryForm.submitId == "nextButton") {
>                    local.state = 5;
>                }
>                break;
>            }
>
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            // Send the order and return a confirmation form
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////

>
>            case 5: {
>                cocoon.sendPage("shop/sendOrder.xsp");
>                local.loop = false;
>                break;
>            }
>        }
>    }
> }
>
> Sample Xml-Document created in the getCart method:
> <?xml version="1.0"?>
> <cart>
>    <cartContent>
>        <content>
>            <product count="5" price="42.23" product="Testprodukt"
> productNo="ABC" totalPrice="211.15"/>
>            <product count="8" price="424.23" product="Testprodudfggkt"
> productNo="ABCD" totalPrice="2141.15"/>
>        </content>
>    </cartContent>
>    <billingAddress/>
>    <shippingAddress/>
> </cart>
>
> Please help me ...
> Chris
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message