Benoit Deshaies wrote:
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...


well, the reason might be the obvious directed examples which are inspired from some original need and are thus likely to communicate some 'intention' (see also the reflection of that in the naming 'insert' 'addmethod')


all of those intentions however don't get in the way of just doing what you need :-)

this basically comes from the fact that there is really nothing magic about the binding: it is (just) a set of xml declarations that quite unmagically map onto executed java code working on the widget-api

from that angle you could also just use that API yourself and make sure the latitude property is present before you call the binding (I mean: rather then doing that from inside the binding. It's really a matter of contract: "what are the pre-conditions for calling that particular binding..." if you negotiate the contract with yourself, then it often boils down to a quite arbitrary decission: just pick the approach that makes you happy)

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());


yep, but you could also just do this in flow-script before calling form.save(report)


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...


I'ld have to check, but I am afraid it is indeed required here and now
if you have the time to check (and can confirm) it might be wise to add this to the bugzilla...
(meaning: I agree, just like context and custom it should be able to work without an id, just don't have time here and now, and bugzilla will help us remember, and possibly inspire people to send in the patch)


while waiting for that patch you can just give it 'some' id, it will not harm you since you will not use the reference to the widget in your script anyway (cut and paste reusability of that part of the binding is the only thing that get's harmed a bit)

regards,
-marc=

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]


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

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



Reply via email to