You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Josh Penza <jo...@gmail.com> on 2007/09/25 18:09:34 UTC

T5 BigDecimalTranslator and Coercion of null to type java.math.BigDecimal

 I have build my own BigDecimalTranslator, because this translator was not
in the current Tapestry Release 5.0.5.

The textfield on my html page has a BigDecimalTranslator attached. But when
the textfield is empty and I submit the page it results in a
NullpointerException:

Coercion of null to type java.math.BigDecimal (via null --> String, String
--> java.math.BigDecimal) failed: *java.lang.NullPointerException
*
Below is the my BigDecimalTranslator Java class, it is almost the same as
other Translator Classes
These classes also return null when the clientValue is blank. But why do I
get a nullpointer then?



*public* *class* BigDecimalTranslator *implements* Translator<BigDecimal>

{

*private* NumberFormat nf = NumberFormat.*getInstance*(Locale.*GERMAN*);

/**

* Parses blank values to null, otherwise parses the client value to a
BigDecimal

*

* *@throws* ValidationException

* if the clientValue can not be parsed

*/

*public* BigDecimal parseClient(String clientValue, Messages messages) *
throws* ValidationException

{

*if* (InternalUtils.*isBlank*(clientValue)) {

*return* *null*;

}

*try
*

{

*return* *new* BigDecimal(nf.parse(clientValue.trim()).toString());

}

*catch* (NumberFormatException ex)

{

*throw* *new* ValidationException(messages.format("number-format-exception",
clientValue));

}

*catch* (ParseException ex)

{

*throw* *new* ValidationException(messages.format("number-parse-exception",
clientValue));

}

}

/**

* Converts null to the blank string, non-null to a string representation.

*/

*public* String toClient(BigDecimal value)

{

*return* value == *null* ? "" : nf.format(value).toString();

}

}

Re: T5 BigDecimalTranslator and Coercion of null to type java.math.BigDecimal

Posted by 蝈蝈龙 <el...@gmail.com>.
It has been fixed in the newest 5.0.6-SNAPSHOT

2007/9/26, Nick Westgate <ni...@key-planning.co.jp>:
>
> Probably this:
> https://issues.apache.org/jira/browse/TAPESTRY-1648
>
> Cheers,
> Nick.
>
>
> Josh Penza wrote:
> >  I have build my own BigDecimalTranslator, because this translator was
> not
> > in the current Tapestry Release 5.0.5.
> >
> > The textfield on my html page has a BigDecimalTranslator attached. But
> when
> > the textfield is empty and I submit the page it results in a
> > NullpointerException:
> >
> > Coercion of null to type java.math.BigDecimal (via null --> String,
> String
> > --> java.math.BigDecimal) failed: *java.lang.NullPointerException
> > *
> > Below is the my BigDecimalTranslator Java class, it is almost the same
> as
> > other Translator Classes
> > These classes also return null when the clientValue is blank. But why do
> I
> > get a nullpointer then?
> >
> >
> >
> > *public* *class* BigDecimalTranslator *implements*
> Translator<BigDecimal>
> >
> > {
> >
> > *private* NumberFormat nf = NumberFormat.*getInstance*(Locale.*GERMAN*);
> >
> > /**
> >
> > * Parses blank values to null, otherwise parses the client value to a
> > BigDecimal
> >
> > *
> >
> > * *@throws* ValidationException
> >
> > * if the clientValue can not be parsed
> >
> > */
> >
> > *public* BigDecimal parseClient(String clientValue, Messages messages) *
> > throws* ValidationException
> >
> > {
> >
> > *if* (InternalUtils.*isBlank*(clientValue)) {
> >
> > *return* *null*;
> >
> > }
> >
> > *try
> > *
> >
> > {
> >
> > *return* *new* BigDecimal(nf.parse(clientValue.trim()).toString());
> >
> > }
> >
> > *catch* (NumberFormatException ex)
> >
> > {
> >
> > *throw* *new* ValidationException(messages.format
> ("number-format-exception",
> > clientValue));
> >
> > }
> >
> > *catch* (ParseException ex)
> >
> > {
> >
> > *throw* *new* ValidationException(messages.format
> ("number-parse-exception",
> > clientValue));
> >
> > }
> >
> > }
> >
> > /**
> >
> > * Converts null to the blank string, non-null to a string
> representation.
> >
> > */
> >
> > *public* String toClient(BigDecimal value)
> >
> > {
> >
> > *return* value == *null* ? "" : nf.format(value).toString();
> >
> > }
> >
> > }
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 BigDecimalTranslator and Coercion of null to type java.math.BigDecimal

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Probably this:
https://issues.apache.org/jira/browse/TAPESTRY-1648

Cheers,
Nick.


Josh Penza wrote:
>  I have build my own BigDecimalTranslator, because this translator was not
> in the current Tapestry Release 5.0.5.
> 
> The textfield on my html page has a BigDecimalTranslator attached. But when
> the textfield is empty and I submit the page it results in a
> NullpointerException:
> 
> Coercion of null to type java.math.BigDecimal (via null --> String, String
> --> java.math.BigDecimal) failed: *java.lang.NullPointerException
> *
> Below is the my BigDecimalTranslator Java class, it is almost the same as
> other Translator Classes
> These classes also return null when the clientValue is blank. But why do I
> get a nullpointer then?
> 
> 
> 
> *public* *class* BigDecimalTranslator *implements* Translator<BigDecimal>
> 
> {
> 
> *private* NumberFormat nf = NumberFormat.*getInstance*(Locale.*GERMAN*);
> 
> /**
> 
> * Parses blank values to null, otherwise parses the client value to a
> BigDecimal
> 
> *
> 
> * *@throws* ValidationException
> 
> * if the clientValue can not be parsed
> 
> */
> 
> *public* BigDecimal parseClient(String clientValue, Messages messages) *
> throws* ValidationException
> 
> {
> 
> *if* (InternalUtils.*isBlank*(clientValue)) {
> 
> *return* *null*;
> 
> }
> 
> *try
> *
> 
> {
> 
> *return* *new* BigDecimal(nf.parse(clientValue.trim()).toString());
> 
> }
> 
> *catch* (NumberFormatException ex)
> 
> {
> 
> *throw* *new* ValidationException(messages.format("number-format-exception",
> clientValue));
> 
> }
> 
> *catch* (ParseException ex)
> 
> {
> 
> *throw* *new* ValidationException(messages.format("number-parse-exception",
> clientValue));
> 
> }
> 
> }
> 
> /**
> 
> * Converts null to the blank string, non-null to a string representation.
> 
> */
> 
> *public* String toClient(BigDecimal value)
> 
> {
> 
> *return* value == *null* ? "" : nf.format(value).toString();
> 
> }
> 
> }
> 

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