cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Huib Verweij" <>
Subject CForms, xindice database and boolean
Date Mon, 13 Jun 2005 18:47:20 GMT
Hi cocooners,

I'm relatively new to Cocoon and have been struggling to get the CForms framework (it's great!)
to work with the embedded xindice database to load and save data for the form. I've solved
this problem thanks to one message I found (can't find it right now) that said to use the
JXPath engine to insert the DOM-tree in the XML pipeline using <jx:out value="#{dom/*}"/>
where 'dom' is the (DOM-) document that comes out of the CForms framework. When you have your
XML-document in the pipeline again you can use Xupdate to save it back to the xindice database.

So that works and it's great! But I had one small problem. When I defined a boolean value
in my form it was saved as:

    <spam-me-baby value="true"/> 

but when I requested the form again I got the error

'Cannot set value of boolean field "spam-me-baby" to a non-Boolean value.'

I suspected that getting the value from the xindice db would be different (i.e. String) than
getting the value from a bean (i.e. Boolean) for instance. I fixed it by editing the file


I inserted the following code in the function setValue, just after the check (object == null):

        if (object instanceof String) {
            object = new Boolean((String) object);

That solved the problem, but now I have a few questions.

1    Was my assumption about the datatype of the value from xindice vs. bean correct?
2    Is my fix correct? (I think there's probably a more elegant way ;-) )
3    Is the described behaviour a bug or a feature? In other words, did I fix something (and
will it still be fixed in the next release?) or haven't I understood how to use the boolean
in a CForm?

The relevant parts of my CForms-definitions are:

*** In the form-definition XML file: ***
    <fd:booleanfield id="spam-me-baby">
      <fd:label><i18n:text key="account_info-field-spam_me_baby">hou mij op de

*** In the binding XML file: ***
    <fb:context xmlns:fb=""
                     path="/db:results/db:result/user" >
  <fb:value id="spam-me-baby" path="personal/preferences/mail/spam-me-baby/@value" />

*** Generating the XML input: ***
  <map:call function="handleForm">
       <map:parameter name="function" value="account2xml"/>
       <map:parameter name="form-definition" value="forms/account.xml"/>
       <map:parameter name="bindingURI" value="forms/binding/account-bind.xml"/>
       <map:parameter name="documentURI" value="xmldb:xindice-embed:///db/god/#//users/user[@id='{ID}']"

(The {ID} comes from the authentication-fw)

*** Saving the XML output: ***

in account.js:

    // save the DOM-tree back to XML using the JXPath framework
   cocoon.sendPage("account-success-pipeline", { "dom":document } );

in the sitemap (internal call):
  <map:generate type="jx" src="jx/account-success-pipeline.jx">
      <map:parameter name="lenient-xpath" value="true"/>

jx/account-success-pipeline.jx contains:

  <jx:out value="#{dom/*[local-name()='results']/*[local-name()='result']/*}"/>

and then xupdate is used to save the XML back to the embedded xindice database.

Regards and many thanks for any answers!


View raw message