Many thanks Marc. That's exactly what I was looking for. For some
reason, I had assumed this was just to add an item to a Collection...

For the simple cases, <fb:insert-bean> will work nicely. In some cases
however, I will need to first check if there is an object already
there. Something like:

if( report.getLatitude() == null )
   report.setLatitude(new GeoCoordinate());

In that case, I think I will use <fb:javascript>. The only problem is
that <fb:javascript> takes the ID of a widget. This initialization
doesn't really apply to any widget in particular...

Benoit Deshaies

--- Marc Portier <[EMAIL PROTECTED]> wrote:
>
http://cocoon.apache.org/2.1/userdocs/forms/binding.html#fb%3Ainsert-bean
> 
> try something along the lines of
> <fb:insert-bean classname="GeoCoordinate" addmethod="setLatitude" />
> 
> before the <fb:value> stuff on the latitude
> 
> this assumes that GeoCoordinate has a constructor that doesn't
> require 
> any arguments, and that your SightingReport has a 
> setLatitude(GeoCoordinate) method (the latter is already assumed by
> the 
> use of jxpath per the paths in your snippet)
> 
> alternatively you could indeed use the javascript or custom binding
> (the first probably somewhat easier)
> 
> HTH,
> -marc=
> 
> Benoit Deshaies wrote:
> > Hi,
> > 
> > I was wondering what was the simplest way to use the Forms Binding
> > Framework to create new objects. I have the following Java model I
> > created a form for:
> > 
> > public class SightingReport {
> >    private String birdName;
> >    private GeoCoordinate latitude;
> >    // gets/sets
> > }
> > 
> > public class GeoCoordinate {
> >    private int deg;
> >    private int min;
> >    private int sec;
> >    // gets/sets
> > }
> > 
> > SightingReport.latitude is initialized to null. My binding file
> looks
> > like this:
> > 
> > <fb:context path="/" >
> >   <fb:value id="birdName" path="birdName"/>
> >   <fb:value id="latDeg" path="latitude/deg"/>
> >   <fb:value id="latMin" path="latitude/min"/>
> >   <fb:value id="latSec" path="latitude/sec"/>
> > </fb:context>
> > 
> > When I invoke form.save(sightingReport), I get the following error:
> > Exception trying to create xpath latitude/deg; Factory is not set
> on
> > the JXPathContext - cannot create path: /latitude.
> > 
> > What would be The Best Way to initialize the latitude object
> (invoke
> > default constructor) ?  <fb:javascript> ? <fb:custom> ?
> > 
> > Many thanks,
> > 
> > Benoit Deshaies




        
                
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to