You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Colin Paul Adams <co...@colina.demon.co.uk> on 2004/07/01 09:32:19 UTC

Binding to an fd:booleanfield

Binding of an xs:boolean attribute in an XML file to a form with an
fd:booleanfield does not work as I would expect it to.

For an attribute a of type xs:boolean, I would expect:

a="true" or a="1" to set the checkbox.
a="false" or a="0" or the absence of an a attribute to unset the
checkbox.
Anything else to signal a validation error.

I find that setting the a attribute to ANYTHING AT ALL (even the empty
string!) sets the checkbox, and only the absence of the attribute
unsets it.

Is this the proper behaviour? 
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:

    Bruno> and it should be spelled with an o: fd:convertor

It works. Hooray!
Thank you for your time and effort.
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 13:59, Colin Paul Adams wrote:
> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
> 
> 
>     Bruno> Looking back at your previous mail:
> 
>     >> <fb:value id="suppression"
>     Bruno> path="boolean(@suppress-recurring)">
>     >> <fb:converter datatype="boolean" type="plain"/> </fb:value>
> 
>     Bruno> the convertor should be in the fd namespace, not fb.
> 
> Makes no difference.

and it should be spelled with an o: fd:convertor

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:


    Bruno> Looking back at your previous mail:

    >> <fb:value id="suppression"
    Bruno> path="boolean(@suppress-recurring)">
    >> <fb:converter datatype="boolean" type="plain"/> </fb:value>

    Bruno> the convertor should be in the fd namespace, not fb.

Makes no difference.
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 13:35, Colin Paul Adams wrote:

>     Bruno> The problem is the following:
>     Bruno> path="boolean(@suppress-recurring)"
> 
>     Bruno> the path element must address a location
>     Bruno> (element/attribute) in you XML file. The expression you
>     Bruno> defined returns a boolean.
> 
>     Bruno> So it should be: path="@suppress-recurring"
> 
>     Bruno> The convertor looks good.
> 
> Thank you.
> If I remove the boolean function, then I get:
> 
> "resource://org/apache/cocoon/forms/flow/javascript/Form.js", 
> line 165: uncaught JavaScript exception: at events2xml 
> (file:/home/colin/onevoice/members/flow/binding.js, Line 12) 
> at (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line
> 165): 
> java.lang.RuntimeException: Cannot set value of boolean field "events.0.suppression" to a non-Boolean value. 

This means that the binding isn't using the convertor.

Looking back at your previous mail:

>       <fb:value id="suppression"    
path="boolean(@suppress-recurring)">
>       <fb:converter datatype="boolean" type="plain"/>
>       </fb:value>

the convertor should be in the fd namespace, not fb.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:

    Bruno> Well, this is exactly why you should have posted what you
    Bruno> tried in the first message, otherwise I could keep
    Bruno> guessing.

You are right, of course.
Also, I was initially trying to add the converter to the form
definition rather than the binding, and you might have spotted that
much earlier than I did.

    Bruno> The problem is the following:
    Bruno> path="boolean(@suppress-recurring)"

    Bruno> the path element must address a location
    Bruno> (element/attribute) in you XML file. The expression you
    Bruno> defined returns a boolean.

    Bruno> So it should be: path="@suppress-recurring"

    Bruno> The convertor looks good.

Thank you.
If I remove the boolean function, then I get:

"resource://org/apache/cocoon/forms/flow/javascript/Form.js", 
line 165: uncaught JavaScript exception: at events2xml 
(file:/home/colin/onevoice/members/flow/binding.js, Line 12) 
at (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line
165): 
java.lang.RuntimeException: Cannot set value of boolean field "events.0.suppression" to a non-Boolean value. 

which is what prompted me to put the boolean() function on in the
first place.

The xml file looks like this:

<?xml version="1.0" encoding="utf-8"?><!-- -*- mode: nxml; -*- -->
<events xmlns="http://colina.demon.co.uk/onevoice/events">
  <event id="ev1" date="2004-06-09" time="19:15" suppress-recurring="true">
    <title>Annual General Meeting</title>
    <location>County Hall - Commitee Room D</location>
  </event>
  <event id="ev2" date="2004-06-20" time="19:15" suppress-recurring="false">
    <title>Caribbean Carnival concert</title>
    <location>Covered market - Black or Lilac</location>
  </event>
  <event id="ev3" date="2004-07-17" suppress-recurring="false">
    <title>Wedding</title>
    <location>St. Chads, Poulton</location>
  </event>
  <event id="ev4" date="2004-07-21" suppress-recurring="true">
    <title>Summer break</title>
    <location/>
  </event>
  <event id="ev5" date="2004-07-28" suppress-recurring="true">
    <title>Summer break</title>
    <location/>
  </event>
  <event id="ev6" date="2004-08-04" suppress-recurring="true">
    <title>Summer break</title>
    <location/>
  </event>
  <event id="ev7" date="2004-08-11" suppress-recurring="true">
    <title>Summer break</title>
    <location/>
  </event>
  <event id="ev8" date="2004-09-26" suppress-recurring="false">
    <title>Wedding Fair</title>
    <location>Warrington</location>
  </event>
  <event id="ev9" date="2004-09-29" time="18:00" finish-at="20:00" suppress-recurring="true">
    <title>Charity concert</title>
    <location>Smithy Arms, Salwick</location>
  </event>
</events>

Changing the true and false values to 1 and 0 make no difference.
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 12:55, Colin Paul Adams wrote:
> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
> 
> 
>     Bruno> plain is the right one
> 
>     Bruno> The above doesn't show where you put that element.
> 
> 
> 
>     Bruno>  Anyway, it's explained over here:
>     Bruno> http://cocoon.apache.org/2.1/userdocs/forms/binding.html#fb%3Avalue
> 
> Not very well, I think, as I can't see any mention of a boolean
> datatype.

That page only explains the concept of using convertors in the binding,
the actual available datatypes are listed at
http://cocoon.apache.org/2.1/userdocs/forms/datatypes.html

though boolean happens to be not there.

> 
>     Bruno> so you have to add a datatype element also.

I meant attribute instead of element.

> 
> Where?
> 
> I've tried this without sucess.:
> 
>   <fb:on-bind>
>         <!-- executed on updates AND right after the insert -->
>       <fb:value id="date" path="@date" />
>       <fb:value id="start-time"  path="@time"  />
>       <fb:value id="finish-time"     path="@finish-at" />
>       <fb:value id="suppression"     path="boolean(@suppress-recurring)">
> 	<fb:converter datatype="boolean" type="plain"/>
>       </fb:value>
>       <fb:value id="title"     path="title"     />
>       <fb:value id="location"     path="location"     />
>     </fb:on-bind>

Well, this is exactly why you should have posted what you tried in the
first message, otherwise I could keep guessing.

The problem is the following:
path="boolean(@suppress-recurring)"

the path element must address a location (element/attribute) in you XML
file. The expression you defined returns a boolean.

So it should be:
path="@suppress-recurring"

The convertor looks good.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:


    Bruno> plain is the right one

    Bruno> The above doesn't show where you put that element.



    Bruno>  Anyway, it's explained over here:
    Bruno> http://cocoon.apache.org/2.1/userdocs/forms/binding.html#fb%3Avalue

Not very well, I think, as I can't see any mention of a boolean
datatype.

    Bruno> so you have to add a datatype element also.

Where?

I've tried this without sucess.:

  <fb:on-bind>
        <!-- executed on updates AND right after the insert -->
      <fb:value id="date" path="@date" />
      <fb:value id="start-time"  path="@time"  />
      <fb:value id="finish-time"     path="@finish-at" />
      <fb:value id="suppression"     path="boolean(@suppress-recurring)">
	<fb:converter datatype="boolean" type="plain"/>
      </fb:value>
      <fb:value id="title"     path="title"     />
      <fb:value id="location"     path="location"     />
    </fb:on-bind>
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 12:22, Colin Paul Adams wrote:
> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
> 
>     Bruno> On Thu, 2004-07-01 at 10:33, Colin Paul Adams wrote:
>     >> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
>     >> 
>     Bruno> Are you using a convertor in the binding?
>     >>  I've tried adding one, but it appears to ignore it, no matter
>     >> what I type.  How should I type it?
> 
>     Bruno> It would be easier if you posted a snippet of what you
>     Bruno> tried.
> 
> I've tried many things.
> 
> Including:
> 
> <fd:converter type="plain"/>
> <fd:converter type="PlainBooleanConverter"/>
> <fd:converter type="fred"/>

plain is the right one

> 
> The last one to see if I get an exception.
> 
> None of these make any difference.

The above doesn't show where you put that element. Anyway, it's
explained over here:
http://cocoon.apache.org/2.1/userdocs/forms/binding.html#fb%3Avalue

so you have to add a datatype element also.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:

    Bruno> On Thu, 2004-07-01 at 10:33, Colin Paul Adams wrote:
    >> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
    >> 
    Bruno> Are you using a convertor in the binding?
    >>  I've tried adding one, but it appears to ignore it, no matter
    >> what I type.  How should I type it?

    Bruno> It would be easier if you posted a snippet of what you
    Bruno> tried.

I've tried many things.

Including:

<fd:converter type="plain"/>
<fd:converter type="PlainBooleanConverter"/>
<fd:converter type="fred"/>

The last one to see if I get an exception.

None of these make any difference.
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 10:33, Colin Paul Adams wrote:
> >>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:
> 
>     Bruno> Are you using a convertor in the binding?
> 
> I've tried adding one, but it appears to ignore it, no matter what I
> type.
> How should I type it?

It would be easier if you posted a snippet of what you tried.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:

    Bruno> Are you using a convertor in the binding?

I've tried adding one, but it appears to ignore it, no matter what I
type.
How should I type it?
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bruno" == Bruno Dumon <br...@outerthought.org> writes:

    Bruno> Are you using a convertor in the binding? Should be I
    Bruno> suppose, otherwise you'd get a classcastexception.

No I'm not - there isn't one documented for it.
And I'm not seeing any exceptions.

    Bruno> The PlainBooleanConvertor (the only convertor there is for
    Bruno> booleans) uses java's Boolean.valueOf which only returns
    Bruno> true if the string value equals, ignoring case, "true".

Where is this then? I can't find it (neither in 2.1.5 nor 2.1 CVS).
-- 
Colin Paul Adams
Preston Lancashire

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


Re: Binding to an fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 09:32, Colin Paul Adams wrote:
> Binding of an xs:boolean attribute in an XML file to a form with an
> fd:booleanfield does not work as I would expect it to.
> 
> For an attribute a of type xs:boolean, I would expect:
> 
> a="true" or a="1" to set the checkbox.
> a="false" or a="0" or the absence of an a attribute to unset the
> checkbox.
> Anything else to signal a validation error.
> 
> I find that setting the a attribute to ANYTHING AT ALL (even the empty
> string!) sets the checkbox, and only the absence of the attribute
> unsets it.
> 
> Is this the proper behaviour? 

Are you using a convertor in the binding? Should be I suppose, otherwise
you'd get a classcastexception.

The PlainBooleanConvertor (the only convertor there is for booleans)
uses java's Boolean.valueOf which only returns true if the string value
equals, ignoring case, "true".

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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