You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Neil Killick <ne...@publicimage.eu.com> on 2004/05/21 04:55:29 UTC

Problem with repeater binding in CForm

Hi,

I'm having problems binding my JavaBean hierarchy to a CFORM. I am setting a default city in my Address bean and it is not being mapped into the form once the form is loaded.

I have an Order bean which holds a collection (ArrayList) of Delivery beans. Each Delivery bean holds an Address bean. I am just trying to set up one Delivery bean to map into the form (i.e. I'm not adding rows, I'm just trying to get the first address to work).

I would really appreciate any help on this. Basically my binding is exactly the same as the contact details example that ships with Cocoon (<cocoon-home>\src\blocks\forms\samples\forms\form2_bind_xml) except I am going down to a deeper path (i.e. delivery/address). My binding is set up in the flowscript:

function getOrderDeliveryForm() {
 var form = new Form("forms/orderDelivery.xml");
 form.createBinding("forms/orderDelivery-binding.xml"); 
 return form; 
}

Here is the other pertinent code and xml:

Flowscript

var form = getOrderDeliveryForm();
var order = new Packages.net.au.whirlwind.data.Order();  
var delivery = new Packages.net.au.whirlwind.data.Delivery();  
var address = new Packages.net.au.whirlwind.data.Address();
address.setCity("Melbourne");
delivery.setId(1);
delivery.setAddress(address);
order.addDelivery(delivery);

form.load(order);
form.showForm( "form-orderDelivery", {"view": param} );
form.save(order);

orderDelivery.xml

<?xml version="1.0"?>
<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
 <fd:widgets>
  <fd:repeater id="deliveries" initial-size="1">
   <fd:label>Delivery</fd:label>
   <fd:hint>this is a hint</fd:hint>
   <fd:help>this is some help</fd:help>
   <fd:widgets>
    <fd:output id="id">
          <fd:datatype base="long"/>
       </fd:output>
    <fd:field id="street" required="false">
     <fd:label>Street</fd:label>
     <fd:datatype base="string"/>
    </fd:field>
    <fd:field id="suburb" required="false">
     <fd:label>Suburb</fd:label>
     <fd:datatype base="string"/>
    </fd:field>
    <fd:field id="city" required="false">
     <fd:label>City</fd:label>
     <fd:datatype base="string"/>
    </fd:field>
    <fd:field id="state" required="false">
     <fd:label>State</fd:label>
     <fd:datatype base="string"/>
    </fd:field>
    <fd:field id="postcode" required="false">
     <fd:label>Postcode</fd:label>
     <fd:datatype base="string">
      <fd:converter type="plain"/>
     </fd:datatype>
     <fd:on-value-changed>
      <javascript>
       optionswidget = event.source.lookupWidget("../options");       
             optionswidget.setSelectionList( h.calcDeliveryOption(), "id", "name" );
          </javascript>
     </fd:on-value-changed>
    </fd:field>
    <fd:field id="country" required="false">
     <fd:label>Country</fd:label>
     <fd:datatype base="string"/>
    </fd:field>
    <fd:field id="options" required="false">
     <fd:label>Options:</fd:label>
     <fd:datatype base="string"/>
     <fd:selection-list>
      <fd:item value="">
       <fd:label>Select a postcode first</fd:label>
      </fd:item>
     </fd:selection-list>
    </fd:field>
    <fd:row-action id="delivery-remove" action-command="delete">
     <fd:label>remove</fd:label>
     <fd:help>help</fd:help>
     <fd:hint>hint</fd:hint>
    </fd:row-action>
   </fd:widgets>
  </fd:repeater>
  <fd:repeater-action id="delivery-add" action-command="add-row" repeater="delivery">
   <fd:label>add address</fd:label>
   <fd:help>help</fd:help>
   <fd:hint>hint</fd:hint>
  </fd:repeater-action>
 </fd:widgets>
</fd:form>

orderDelivery-binding.xml

<?xml version="1.0"?>
<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" path="/">
 <fb:repeater id="deliveries" parent-path="deliveries" row-path="delivery">
  <fb:identity>
      <fb:value id="id" path="@id"/>
   </fb:identity>
  <fb:on-bind>
   <fb:value id="street" path="address/street"/>
   <fb:value id="suburb" path="address/suburb"/>
   <fb:value id="city" path="address/city"/>
   <fb:value id="state" path="address/state"/>
   <fb:value id="postcode" path="address/postCode"/>
   <fb:value id="country" path="address/country"/>
   <fb:value id="options" path="method"/>
  </fb:on-bind>
 </fb:repeater>
</fb:context>

I have also tried setting the parent-path to ".", again to no avail.

What am I doing wrong? Basically I don't get any errors, but "Melbourne" simply does not appear in the city field.

Thanks in advance.

Regards, 
Neil Killick
------
Public Image
Creative Strategy & Production 
for Print, Online & Broadcast Media

Public Image Software
The SONART family of 
Management Information Systems
for the creative industries

Melbourne Studios:
Telephone +61 3 9650 0650
Facsimile +61 3 9650 0770

Re: Problem with repeater binding in CForm

Posted by Marc Portier <mp...@outerthought.org>.

Neil Killick wrote:
> Marc,
> 
> The code you wrote is exactly what I am doing. The Order bean does have a
> setDeliveries method (there would be compile errors if it didn't).
> 
> It's a baffling one!
> 

in cases like this, I just fire up a remote debugging session and step 
through things

--> the stack trace on the error mentioned earlier should 've given you 
a hint on where to set the breakpoint

--> start cocoon in the jetty context with debugging enabled through: 
./cocoon.sh servlet-debug

--> use your debugger (eclipse?) to attach to the vm and hit the browser 
for the uri that causes the trouble

--> step through your code

am afraid that the distance between us, (and my dumb head I admit) 
prevents me to see the obvious here

regards,
-marc=

> Thanks,
> 
> Neil
> 
> 
> ----- Original Message -----
> From: "Marc Portier" <mp...@outerthought.org>
> To: <us...@cocoon.apache.org>
> Sent: Tuesday, May 25, 2004 5:14 AM
> Subject: Re: Problem with repeater binding in CForm
> 
> 
> 
>>
>>Neil Killick wrote:
>>
>>>As an aside, the following code works fine if put after the
> 
> form.save(order)
> 
>>>line:
>>>
>>>var address = new Packages.net.au.whirlwind.data.Address();
>>>var deliveries = order.getDeliveries();
>>>var model = form.getModel();
>>>var deliveryModel = form.lookupWidget("deliveries/0");
>>>address.setStreet(deliveryModel.lookupWidget("street").getValue());
>>>address.setCity(deliveryModel.lookupWidget("city").getValue());
>>>address.setSuburb(deliveryModel.lookupWidget("suburb").getValue());
>>>address.setState(deliveryModel.lookupWidget("state").getValue());
>>>address.setPostCode(deliveryModel.lookupWidget("postcode").getValue());
>>>
>>>This code grabs the values out of the form fine. So if this manual
> 
> approach
> 
>>>works, why doesn't the binding?
>>>
>>
>>I think this is not the part that is causing the problem
>>I would guess that reading from the form is ok, but setting the values
>>to your bean is not
>>
>>the questions then are:
>>1/ how do you programmatically add the address to the deliveries
>>is it this?
>>
>>var delivery = new Packages.net.au.whirlwind.data.Delivery()
>>delivery.setAddress(address);
>>delivereries.add(delivery);
>>
>>2/ how do you programmatically add the deliveries to the order
>>is it this?
>>
>>order.setDeliveries(deliveries) --> this method seems to be missing
>>according to the error?
>>
>>regards,
>>-marc=
>>
>>
>>>----- Original Message -----
>>>From: "Marc Portier" <mp...@outerthought.org>
>>>To: <us...@cocoon.apache.org>
>>>Sent: Friday, May 21, 2004 6:06 PM
>>>Subject: Re: Problem with repeater binding in CForm
>>>
>>>
>>>
>>>
>>>>Neil Killick wrote:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>
>>>>
>>>><snip what="sample snippets" />
>>>>
>>>>>I have also tried setting the parent-path to ".", again to no avail.
>>>>>
>>>>
>>>>afaics that would be what you need, supposing the java call is
>>>>order.getDelivery(index) and not
> 
> order.getDeliveries().getDelivery(index);
> 
>>>>
>>>>>What am I doing wrong? Basically I don't get any errors, but
> 
> "Melbourne"
> 
>>>>>simply does not appear in the city field.
>>>>>
>>>>
>>>>in fact with a wrong parent-path you wouldn't see any of the other
>>>>fields of address either (were those working?)
>>>>
>>>>hm, you do have a getCity() on the address bean, right?
>>>>try setting the lenient="false" on the binding, that would cause more
>>>>errors if something isn't right
>>>>
>>>>HTH,
>>>>-marc=
>>>>--
>>>>Marc Portier                            http://outerthought.org/
>>>>Outerthought - Open Source, Java & XML Competence Support Center
>>>>Read my weblog at                http://blogs.cocoondev.org/mpo/
>>>>mpo@outerthought.org                              mpo@apache.org
>>>>
>>>>---------------------------------------------------------------------
>>>>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
>>>
>>
>>--
>>Marc Portier                            http://outerthought.org/
>>Outerthought - Open Source, Java & XML Competence Support Center
>>Read my weblog at                http://blogs.cocoondev.org/mpo/
>>mpo@outerthought.org                              mpo@apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>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
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org

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


Re: Problem with repeater binding in CForm

Posted by Neil Killick <ne...@publicimage.eu.com>.
Marc,

The code you wrote is exactly what I am doing. The Order bean does have a
setDeliveries method (there would be compile errors if it didn't).

It's a baffling one!

Thanks,

Neil


----- Original Message -----
From: "Marc Portier" <mp...@outerthought.org>
To: <us...@cocoon.apache.org>
Sent: Tuesday, May 25, 2004 5:14 AM
Subject: Re: Problem with repeater binding in CForm


>
>
> Neil Killick wrote:
> > As an aside, the following code works fine if put after the
form.save(order)
> > line:
> >
> > var address = new Packages.net.au.whirlwind.data.Address();
> > var deliveries = order.getDeliveries();
> > var model = form.getModel();
> > var deliveryModel = form.lookupWidget("deliveries/0");
> > address.setStreet(deliveryModel.lookupWidget("street").getValue());
> > address.setCity(deliveryModel.lookupWidget("city").getValue());
> > address.setSuburb(deliveryModel.lookupWidget("suburb").getValue());
> > address.setState(deliveryModel.lookupWidget("state").getValue());
> > address.setPostCode(deliveryModel.lookupWidget("postcode").getValue());
> >
> > This code grabs the values out of the form fine. So if this manual
approach
> > works, why doesn't the binding?
> >
>
> I think this is not the part that is causing the problem
> I would guess that reading from the form is ok, but setting the values
> to your bean is not
>
> the questions then are:
> 1/ how do you programmatically add the address to the deliveries
> is it this?
>
> var delivery = new Packages.net.au.whirlwind.data.Delivery()
> delivery.setAddress(address);
> delivereries.add(delivery);
>
> 2/ how do you programmatically add the deliveries to the order
> is it this?
>
> order.setDeliveries(deliveries) --> this method seems to be missing
> according to the error?
>
> regards,
> -marc=
>
> >
> > ----- Original Message -----
> > From: "Marc Portier" <mp...@outerthought.org>
> > To: <us...@cocoon.apache.org>
> > Sent: Friday, May 21, 2004 6:06 PM
> > Subject: Re: Problem with repeater binding in CForm
> >
> >
> >
> >>
> >>Neil Killick wrote:
> >>
> >>
> >>>Hi,
> >>>
> >>>
> >>
> >><snip what="sample snippets" />
> >>
> >>>I have also tried setting the parent-path to ".", again to no avail.
> >>>
> >>
> >>afaics that would be what you need, supposing the java call is
> >>order.getDelivery(index) and not
order.getDeliveries().getDelivery(index);
> >>
> >>
> >>>What am I doing wrong? Basically I don't get any errors, but
"Melbourne"
> >>>simply does not appear in the city field.
> >>>
> >>
> >>in fact with a wrong parent-path you wouldn't see any of the other
> >>fields of address either (were those working?)
> >>
> >>hm, you do have a getCity() on the address bean, right?
> >>try setting the lenient="false" on the binding, that would cause more
> >>errors if something isn't right
> >>
> >>HTH,
> >>-marc=
> >>--
> >>Marc Portier                            http://outerthought.org/
> >>Outerthought - Open Source, Java & XML Competence Support Center
> >>Read my weblog at                http://blogs.cocoondev.org/mpo/
> >>mpo@outerthought.org                              mpo@apache.org
> >>
> >>---------------------------------------------------------------------
> >>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
> >
>
> --
> Marc Portier                            http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> Read my weblog at                http://blogs.cocoondev.org/mpo/
> mpo@outerthought.org                              mpo@apache.org
>
>
>
> ---------------------------------------------------------------------
> 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


Re: Problem with repeater binding in CForm

Posted by Marc Portier <mp...@outerthought.org>.

Neil Killick wrote:
> As an aside, the following code works fine if put after the form.save(order)
> line:
> 
> var address = new Packages.net.au.whirlwind.data.Address();
> var deliveries = order.getDeliveries();
> var model = form.getModel();
> var deliveryModel = form.lookupWidget("deliveries/0");
> address.setStreet(deliveryModel.lookupWidget("street").getValue());
> address.setCity(deliveryModel.lookupWidget("city").getValue());
> address.setSuburb(deliveryModel.lookupWidget("suburb").getValue());
> address.setState(deliveryModel.lookupWidget("state").getValue());
> address.setPostCode(deliveryModel.lookupWidget("postcode").getValue());
> 
> This code grabs the values out of the form fine. So if this manual approach
> works, why doesn't the binding?
> 

I think this is not the part that is causing the problem
I would guess that reading from the form is ok, but setting the values
to your bean is not

the questions then are:
1/ how do you programmatically add the address to the deliveries
is it this?

var delivery = new Packages.net.au.whirlwind.data.Delivery()
delivery.setAddress(address);
delivereries.add(delivery);

2/ how do you programmatically add the deliveries to the order
is it this?

order.setDeliveries(deliveries) --> this method seems to be missing 
according to the error?

regards,
-marc=

> 
> ----- Original Message -----
> From: "Marc Portier" <mp...@outerthought.org>
> To: <us...@cocoon.apache.org>
> Sent: Friday, May 21, 2004 6:06 PM
> Subject: Re: Problem with repeater binding in CForm
> 
> 
> 
>>
>>Neil Killick wrote:
>>
>>
>>>Hi,
>>>
>>>
>>
>><snip what="sample snippets" />
>>
>>>I have also tried setting the parent-path to ".", again to no avail.
>>>
>>
>>afaics that would be what you need, supposing the java call is
>>order.getDelivery(index) and not order.getDeliveries().getDelivery(index);
>>
>>
>>>What am I doing wrong? Basically I don't get any errors, but "Melbourne"
>>>simply does not appear in the city field.
>>>
>>
>>in fact with a wrong parent-path you wouldn't see any of the other
>>fields of address either (were those working?)
>>
>>hm, you do have a getCity() on the address bean, right?
>>try setting the lenient="false" on the binding, that would cause more
>>errors if something isn't right
>>
>>HTH,
>>-marc=
>>--
>>Marc Portier                            http://outerthought.org/
>>Outerthought - Open Source, Java & XML Competence Support Center
>>Read my weblog at                http://blogs.cocoondev.org/mpo/
>>mpo@outerthought.org                              mpo@apache.org
>>
>>---------------------------------------------------------------------
>>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
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org



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


Re: Problem with repeater binding in CForm

Posted by Neil Killick <ne...@publicimage.eu.com>.
As an aside, the following code works fine if put after the form.save(order)
line:

var address = new Packages.net.au.whirlwind.data.Address();
var deliveries = order.getDeliveries();
var model = form.getModel();
var deliveryModel = form.lookupWidget("deliveries/0");
address.setStreet(deliveryModel.lookupWidget("street").getValue());
address.setCity(deliveryModel.lookupWidget("city").getValue());
address.setSuburb(deliveryModel.lookupWidget("suburb").getValue());
address.setState(deliveryModel.lookupWidget("state").getValue());
address.setPostCode(deliveryModel.lookupWidget("postcode").getValue());

This code grabs the values out of the form fine. So if this manual approach
works, why doesn't the binding?


----- Original Message -----
From: "Marc Portier" <mp...@outerthought.org>
To: <us...@cocoon.apache.org>
Sent: Friday, May 21, 2004 6:06 PM
Subject: Re: Problem with repeater binding in CForm


>
>
> Neil Killick wrote:
>
> > Hi,
> >
> >
>
> <snip what="sample snippets" />
>
> >
> > I have also tried setting the parent-path to ".", again to no avail.
> >
>
> afaics that would be what you need, supposing the java call is
> order.getDelivery(index) and not order.getDeliveries().getDelivery(index);
>
> > What am I doing wrong? Basically I don't get any errors, but "Melbourne"
> > simply does not appear in the city field.
> >
>
> in fact with a wrong parent-path you wouldn't see any of the other
> fields of address either (were those working?)
>
> hm, you do have a getCity() on the address bean, right?
> try setting the lenient="false" on the binding, that would cause more
> errors if something isn't right
>
> HTH,
> -marc=
> --
> Marc Portier                            http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> Read my weblog at                http://blogs.cocoondev.org/mpo/
> mpo@outerthought.org                              mpo@apache.org
>
> ---------------------------------------------------------------------
> 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


Re: Problem with repeater binding in CForm

Posted by Neil Killick <ne...@publicimage.eu.com>.
Thanks for your reply Marc.

Using "lenient=false" I am now seeing an exception "Cannot find specified
propery (property setDeliveries)". I get this if I set parent-path to "." or
to "deliveries". I get no other errors.

"deliveries" is defined as an attribute in the Order bean, and is an
ArrayList. So there are getDeliveries() and setDeliveries(ArrayList
deliveries) methods defined.

And, yes, the Address bean does have setCity().

Any more ideas?

Cheers,

Neil


----- Original Message -----
From: "Marc Portier" <mp...@outerthought.org>
To: <us...@cocoon.apache.org>
Sent: Friday, May 21, 2004 6:06 PM
Subject: Re: Problem with repeater binding in CForm


>
>
> Neil Killick wrote:
>
> > Hi,
> >
> >
>
> <snip what="sample snippets" />
>
> >
> > I have also tried setting the parent-path to ".", again to no avail.
> >
>
> afaics that would be what you need, supposing the java call is
> order.getDelivery(index) and not order.getDeliveries().getDelivery(index);
>
> > What am I doing wrong? Basically I don't get any errors, but "Melbourne"
> > simply does not appear in the city field.
> >
>
> in fact with a wrong parent-path you wouldn't see any of the other
> fields of address either (were those working?)
>
> hm, you do have a getCity() on the address bean, right?
> try setting the lenient="false" on the binding, that would cause more
> errors if something isn't right
>
> HTH,
> -marc=
> --
> Marc Portier                            http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> Read my weblog at                http://blogs.cocoondev.org/mpo/
> mpo@outerthought.org                              mpo@apache.org
>
> ---------------------------------------------------------------------
> 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


Re: Problem with repeater binding in CForm

Posted by Marc Portier <mp...@outerthought.org>.

Neil Killick wrote:

> Hi,
>  
>

<snip what="sample snippets" />

>  
> I have also tried setting the parent-path to ".", again to no avail.
>  

afaics that would be what you need, supposing the java call is 
order.getDelivery(index) and not order.getDeliveries().getDelivery(index);

> What am I doing wrong? Basically I don't get any errors, but "Melbourne" 
> simply does not appear in the city field.
>  

in fact with a wrong parent-path you wouldn't see any of the other 
fields of address either (were those working?)

hm, you do have a getCity() on the address bean, right?
try setting the lenient="false" on the binding, that would cause more 
errors if something isn't right

HTH,
-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org

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