You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/12/02 15:44:56 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

vgritsenko    2003/12/02 06:44:56

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor
                        PlainBooleanConvertor.java
  Log:
  Check for null/empty values.
  Allows to distinguish between null, Boolean.TRUE, and Boolean.FALSE
  
  Revision  Changes    Path
  1.2       +3 -0      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java
  
  Index: PlainBooleanConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PlainBooleanConvertor.java	12 Aug 2003 12:54:45 -0000	1.1
  +++ PlainBooleanConvertor.java	2 Dec 2003 14:44:56 -0000	1.2
  @@ -7,6 +7,9 @@
    */
   public class PlainBooleanConvertor implements Convertor {
       public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
  +        if (value == null || value.length() == 0) {
  +            return "";
  +        }
           return Boolean.valueOf(value);
       }
   
  
  
  

Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Vadim Gritsenko <va...@verizon.net>.
Vadim Gritsenko wrote:

> Bruno Dumon wrote:
> ...
>
>> Aha, I finally got it. The problem is that the selection list doesn't
>> allow an empty (or null) value.
>>
>
> Is it the problem with selection list only, or with some other classes 
> too?
>
>
>> If you look into the generated HTML
>> source you'll see that the "Dunno" choice also has a value of "false". I
>> think this is something that should be fixed in the selection lists,
>> i.e. if the wd:item/@value attribute is empty, don't call the convertor
>> but put a null value in the selection list. (and vice-versa, if the
>> value in the selection list is null, don't call the convertor but output
>> an empty string)
>

Done. Hope nothing got broke because of this (can somebody cross-check?)

Vadim



Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Vadim Gritsenko <va...@verizon.net>.
Bruno Dumon wrote:
...

>Aha, I finally got it. The problem is that the selection list doesn't
>allow an empty (or null) value.
>

Is it the problem with selection list only, or with some other classes too?


>If you look into the generated HTML
>source you'll see that the "Dunno" choice also has a value of "false". I
>think this is something that should be fixed in the selection lists,
>i.e. if the wd:item/@value attribute is empty, don't call the convertor
>but put a null value in the selection list. (and vice-versa, if the
>value in the selection list is null, don't call the convertor but output
>an empty string)
>

If it is selection list problem, then yes, I agree.

Vadim




Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Bruno Dumon <br...@outerthought.org>.
sorry for the late follow-up, I've been out-of-office the last two days.

On Tue, 2003-12-02 at 23:04, Vadim Gritsenko wrote:
> Bruno Dumon wrote:
> 
> >On Tue, 2003-12-02 at 18:02, Vadim Gritsenko wrote:
> >  
> >
> >>Bruno Dumon wrote:
> >>
> ..
> 
> >>>My intuition tells me that a BooleanConvertor should return a Boolean
> >>>object.
> >>>
> >>>What's the purpose of this, IOW what is affected by this? 
> >>>
> >>>      
> >>>
> >>Commit log says it all: instead of null, JavaBean gets Boolean.FALSE, 
> >>which is, as I believe, wrong: you should not bind FALSE instead of null.
> >>    
> >>
> >
> >Still trying to understand how you're using it in order to fully
> >understand the problem:
> >Where exactly are you using the convertor? In the binding definition? If
> >the Javabean holds a Boolean property, why do you need the convertor
> >there?
> >  
> >
> 
> Ok, step by step. Here is model:
>     <wd:field id="hasSomething">
>       <wd:datatype base="boolean">
>         <wd:convertor type="plain"/>
>       </wd:datatype>
>       <wd:selection-list>
>         <wd:item value="true">
>           <wd:label>Yes</wd:label>
>         </wd:item>
>         <wd:item value="false">
>           <wd:label>No</wd:label>
>         </wd:item>
>         <wd:item value="">
>           <wd:label>Dunno</wd:label>
>         </wd:item>
>       </wd:selection-list>
>     </wd:field>
> 
> Template:
>   <wt:widget id="hasSomething">
>     <wi:styling list-type="radio" list-orientation="horizontal"/>
>   </wt:widget>
> 
> Binding:
>     <wb:value id="hasSomething" path="something"/>
> 
> Bean:
>     void setSomething(Boolean);
>     Boolean getSomething();
> 
> 
> It did not work before the patch; convertor was returning Boolean.FALSE 
> when, in fact, the value was NULL.

Aha, I finally got it. The problem is that the selection list doesn't
allow an empty (or null) value. If you look into the generated HTML
source you'll see that the "Dunno" choice also has a value of "false". I
think this is something that should be fixed in the selection lists,
i.e. if the wd:item/@value attribute is empty, don't call the convertor
but put a null value in the selection list. (and vice-versa, if the
value in the selection list is null, don't call the convertor but output
an empty string)

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


Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Vadim Gritsenko <va...@verizon.net>.
Bruno Dumon wrote:

>On Tue, 2003-12-02 at 18:02, Vadim Gritsenko wrote:
>  
>
>>Bruno Dumon wrote:
>>
..

>>>My intuition tells me that a BooleanConvertor should return a Boolean
>>>object.
>>>
>>>What's the purpose of this, IOW what is affected by this? 
>>>
>>>      
>>>
>>Commit log says it all: instead of null, JavaBean gets Boolean.FALSE, 
>>which is, as I believe, wrong: you should not bind FALSE instead of null.
>>    
>>
>
>Still trying to understand how you're using it in order to fully
>understand the problem:
>Where exactly are you using the convertor? In the binding definition? If
>the Javabean holds a Boolean property, why do you need the convertor
>there?
>  
>

Ok, step by step. Here is model:
    <wd:field id="hasSomething">
      <wd:datatype base="boolean">
        <wd:convertor type="plain"/>
      </wd:datatype>
      <wd:selection-list>
        <wd:item value="true">
          <wd:label>Yes</wd:label>
        </wd:item>
        <wd:item value="false">
          <wd:label>No</wd:label>
        </wd:item>
        <wd:item value="">
          <wd:label>Dunno</wd:label>
        </wd:item>
      </wd:selection-list>
    </wd:field>

Template:
  <wt:widget id="hasSomething">
    <wi:styling list-type="radio" list-orientation="horizontal"/>
  </wt:widget>

Binding:
    <wb:value id="hasSomething" path="something"/>

Bean:
    void setSomething(Boolean);
    Boolean getSomething();


It did not work before the patch; convertor was returning Boolean.FALSE 
when, in fact, the value was NULL.

Vadim



Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2003-12-02 at 18:02, Vadim Gritsenko wrote:
> Bruno Dumon wrote:
> 
> >On Tue, 2003-12-02 at 15:49, Vadim Gritsenko wrote:
> >  
> >
> >>vgritsenko@apache.org wrote:
> >>
> >>    
> >>
> >>>  Index: PlainBooleanConvertor.java
> >>> ===================================================================
> >>> RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
> >>> retrieving revision 1.1
> >>> retrieving revision 1.2
> >>> diff -u -r1.1 -r1.2
> >>> --- PlainBooleanConvertor.java	12 Aug 2003 12:54:45 -0000	1.1
> >>> +++ PlainBooleanConvertor.java	2 Dec 2003 14:44:56 -0000	1.2
> >>> @@ -7,6 +7,9 @@
> >>>   */
> >>>  public class PlainBooleanConvertor implements Convertor {
> >>>      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
> >>> +        if (value == null || value.length() == 0) {
> >>> +            return "";
> >>> +        }
> >>>          return Boolean.valueOf(value);
> >>>      }
> >>>      
> >>>
> >>Can somebody else confirm that this is ok? Works for me...
> >>    
> >>
> >
> >My intuition tells me that a BooleanConvertor should return a Boolean
> >object.
> >
> >What's the purpose of this, IOW what is affected by this?
> >  
> >
> 
> Commit log says it all: instead of null, JavaBean gets Boolean.FALSE, 
> which is, as I believe, wrong: you should not bind FALSE instead of null.

Still trying to understand how you're using it in order to fully
understand the problem:
Where exactly are you using the convertor? In the binding definition? If
the Javabean holds a Boolean property, why do you need the convertor
there?

Regardless of this, it seems to me that if there is no value to convert,
the convertor shouldn't be called in the first place.

> 
> I tried to return null from the convertor, but it caused exception down 
> the road, and empty string worked out Ok.
> 
> Vadim
-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Vadim Gritsenko <va...@verizon.net>.
Bruno Dumon wrote:

>On Tue, 2003-12-02 at 15:49, Vadim Gritsenko wrote:
>  
>
>>vgritsenko@apache.org wrote:
>>
>>    
>>
>>>  Index: PlainBooleanConvertor.java
>>> ===================================================================
>>> RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
>>> retrieving revision 1.1
>>> retrieving revision 1.2
>>> diff -u -r1.1 -r1.2
>>> --- PlainBooleanConvertor.java	12 Aug 2003 12:54:45 -0000	1.1
>>> +++ PlainBooleanConvertor.java	2 Dec 2003 14:44:56 -0000	1.2
>>> @@ -7,6 +7,9 @@
>>>   */
>>>  public class PlainBooleanConvertor implements Convertor {
>>>      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
>>> +        if (value == null || value.length() == 0) {
>>> +            return "";
>>> +        }
>>>          return Boolean.valueOf(value);
>>>      }
>>>      
>>>
>>Can somebody else confirm that this is ok? Works for me...
>>    
>>
>
>My intuition tells me that a BooleanConvertor should return a Boolean
>object.
>
>What's the purpose of this, IOW what is affected by this?
>  
>

Commit log says it all: instead of null, JavaBean gets Boolean.FALSE, 
which is, as I believe, wrong: you should not bind FALSE instead of null.

I tried to return null from the convertor, but it caused exception down 
the road, and empty string worked out Ok.

Vadim



Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2003-12-02 at 15:49, Vadim Gritsenko wrote:
> vgritsenko@apache.org wrote:
> 
> >   Index: PlainBooleanConvertor.java
> >  ===================================================================
> >  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
> >  retrieving revision 1.1
> >  retrieving revision 1.2
> >  diff -u -r1.1 -r1.2
> >  --- PlainBooleanConvertor.java	12 Aug 2003 12:54:45 -0000	1.1
> >  +++ PlainBooleanConvertor.java	2 Dec 2003 14:44:56 -0000	1.2
> >  @@ -7,6 +7,9 @@
> >    */
> >   public class PlainBooleanConvertor implements Convertor {
> >       public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
> >  +        if (value == null || value.length() == 0) {
> >  +            return "";
> >  +        }
> >           return Boolean.valueOf(value);
> >       }
> >  
> >
> 
> Can somebody else confirm that this is ok? Works for me...

My intuition tells me that a BooleanConvertor should return a Boolean
object.

What's the purpose of this, IOW what is affected by this?

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


Re: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor PlainBooleanConvertor.java

Posted by Vadim Gritsenko <va...@verizon.net>.
vgritsenko@apache.org wrote:

>   Index: PlainBooleanConvertor.java
>  ===================================================================
>  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
>  retrieving revision 1.1
>  retrieving revision 1.2
>  diff -u -r1.1 -r1.2
>  --- PlainBooleanConvertor.java	12 Aug 2003 12:54:45 -0000	1.1
>  +++ PlainBooleanConvertor.java	2 Dec 2003 14:44:56 -0000	1.2
>  @@ -7,6 +7,9 @@
>    */
>   public class PlainBooleanConvertor implements Convertor {
>       public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
>  +        if (value == null || value.length() == 0) {
>  +            return "";
>  +        }
>           return Boolean.valueOf(value);
>       }
>  
>

Can somebody else confirm that this is ok? Works for me...

Vadim