You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Joerg Heinicke <jo...@gmx.de> on 2004/03/24 16:05:28 UTC

[cforms] writing my own data type

I'm trying to write my own data type implementation, but I fail on access
restrictions in the AbstractDataType of Woody/Cocoon Forms.

I want to have a data type that's based on long and formatted as currency,
similar to the one already existing, but

1. working:

When having

  <wd:datatype base="long">
    <wd:convertor type="formatting" variant="currency"/>
  </wd:datatype>

in the form definition I get my amount nicely formatted, but can not save it
back. Even a value '123' ends in a ParseException. As I do not want to dive into
XReporter I decided to write my own one without XReporter.

2. and not ignoring cents:

When having the long value 1234567 it gets formatted as "1.234.567,00 €",
meaning that I can never save cents. It should be "12.345,67 €".


Back to the actual problem:

I extended AbstractDataType and AbstractDataTypeBuilder and copied more or less
the LongType and LongTypeBuilder. But I fail at

    type.setArrayType(arrayType);
    type.setBuilder(this);

as these both methods have default access. Is there any specific reason for it?
Even passing arrayType and this to the constructor of my AmountType would only
work if the methods would have protected access. So what about changing the
access of those methods to at least protected, maybe public?

Some comments on the existing long/formatting/currency issue?

Regards,

Joerg


Re: [cforms] writing my own data type

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2004-03-24 at 19:33, Joerg Heinicke wrote:
<snip/>
> >>Back to the actual problem:
> >>
> >>I extended AbstractDataType and AbstractDataTypeBuilder and copied more or less
> >>the LongType and LongTypeBuilder. But I fail at
> >>
> >>    type.setArrayType(arrayType);
> >>    type.setBuilder(this);
> >>
> >>as these both methods have default access. Is there any specific reason for it?
> >>Even passing arrayType and this to the constructor of my AmountType would only
> >>work if the methods would have protected access. So what about changing the
> >>access of those methods to at least protected, maybe public?
> > 
> > 
> > protected seems good, I don't know why I didn't make them protected.
> 
> I will change it. What exactly are these both methods good or needed 
> for? I found only selection lists in relation to the field 
> AbstractDataType.builder. My own datatype works without calling both 
> methods.

arrayType indicates that the datatype represents an array of objects
(i.e. an array of longs). This is the case for the multivaluefield.

The builder is indeed needed by selection lists, because a selection
list can include a convertor specification, and the builder is then
needed to build that convertor.

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


Re: [cforms] writing my own data type

Posted by Joerg Heinicke <jo...@gmx.de>.
On 24.03.2004 19:01, Bruno Dumon wrote:

>>I'm trying to write my own data type implementation, but I fail on access
>>restrictions in the AbstractDataType of Woody/Cocoon Forms.
>>
>>I want to have a data type that's based on long and formatted as currency,
>>similar to the one already existing, but
>>
>>1. working:
>>
>>When having
>>
>>  <wd:datatype base="long">
>>    <wd:convertor type="formatting" variant="currency"/>
>>  </wd:datatype>
>>
>>in the form definition I get my amount nicely formatted, but can not save it
>>back. Even a value '123' ends in a ParseException. As I do not want to dive into
>>XReporter I decided to write my own one without XReporter.
> 
> 
> The formatting convertors simply use the java.text.DecimalFormat class
> (the xreporter classes used there are simply a small wrapper to either
> use the JDK version of that class or the one that ships with IBM's ICU4J
> library).

Hmm, strange. This means in general java.text.DecimalFormat returning 
1234567 from the formatted "1.234.567,00 €" should work, shouldn't it?

>>2. and not ignoring cents:
>>
>>When having the long value 1234567 it gets formatted as "1.234.567,00 €",
>>meaning that I can never save cents. It should be "12.345,67 €".
> 
> 
> How can it possibly know that the value you entered should be divided by
> 100?

I did not expected it to work, take a as a hint for improvement, e.g. by 
adding a parameter multiplier. For percent the current behaviour is even 
worse: You can only specify values that are multiples of 100 %.

> Anyway, don't you need only a custom convertor? A long stays a long I
> guess?

Yes, you are right.

>>Back to the actual problem:
>>
>>I extended AbstractDataType and AbstractDataTypeBuilder and copied more or less
>>the LongType and LongTypeBuilder. But I fail at
>>
>>    type.setArrayType(arrayType);
>>    type.setBuilder(this);
>>
>>as these both methods have default access. Is there any specific reason for it?
>>Even passing arrayType and this to the constructor of my AmountType would only
>>work if the methods would have protected access. So what about changing the
>>access of those methods to at least protected, maybe public?
> 
> 
> protected seems good, I don't know why I didn't make them protected.

I will change it. What exactly are these both methods good or needed 
for? I found only selection lists in relation to the field 
AbstractDataType.builder. My own datatype works without calling both 
methods.

Thanks for your answer,

Joerg

Re: [cforms] writing my own data type

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2004-03-24 at 16:05, Joerg Heinicke wrote:
> I'm trying to write my own data type implementation, but I fail on access
> restrictions in the AbstractDataType of Woody/Cocoon Forms.
> 
> I want to have a data type that's based on long and formatted as currency,
> similar to the one already existing, but
> 
> 1. working:
> 
> When having
> 
>   <wd:datatype base="long">
>     <wd:convertor type="formatting" variant="currency"/>
>   </wd:datatype>
> 
> in the form definition I get my amount nicely formatted, but can not save it
> back. Even a value '123' ends in a ParseException. As I do not want to dive into
> XReporter I decided to write my own one without XReporter.

The formatting convertors simply use the java.text.DecimalFormat class
(the xreporter classes used there are simply a small wrapper to either
use the JDK version of that class or the one that ships with IBM's ICU4J
library).

> 
> 2. and not ignoring cents:
> 
> When having the long value 1234567 it gets formatted as "1.234.567,00 €",
> meaning that I can never save cents. It should be "12.345,67 €".

How can it possibly know that the value you entered should be divided by
100?

Anyway, don't you need only a custom convertor? A long stays a long I
guess?

> 
> Back to the actual problem:
> 
> I extended AbstractDataType and AbstractDataTypeBuilder and copied more or less
> the LongType and LongTypeBuilder. But I fail at
> 
>     type.setArrayType(arrayType);
>     type.setBuilder(this);
> 
> as these both methods have default access. Is there any specific reason for it?
> Even passing arrayType and this to the constructor of my AmountType would only
> work if the methods would have protected access. So what about changing the
> access of those methods to at least protected, maybe public?

protected seems good, I don't know why I didn't make them protected.

> 
> Some comments on the existing long/formatting/currency issue?
> 
> Regards,
> 
> Joerg
-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org