You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by charlie brown <ch...@googlemail.com> on 2006/01/12 13:53:34 UTC

Number Translator Problem

Hi,
I am writing a tap 4 component and want to use the translated field support
to convert the user input to an integer.
However when I enter a numeric value into the field, the translator returns
a Long, and I get a class cast exception when try to set it to a value.

@Parameter(defaultValue = "translator:number")
public abstract Translator getTranslator();

InjectObject("service:tapestry.form.TranslatedFieldSupport")
public abstract TranslatedFieldSupport getTranslatedFieldSupport();

Integer dayInt = (Integer) getTranslatedFieldSupport().parse(this,
dayValue);

I had a look through the source but I couldnt find a way of specifing the
type of Number to return from the translator.

I am able to parse the input myself and everything works fine

Can anyone help?

Re: Number Translator Problem

Posted by Kent Tong <ke...@cpttm.org.mo>.
charlie brown <charliesno <at> googlemail.com> writes:

> I am writing a tap 4 component and want to use the translated field support
> to convert the user input to an integer.
> However when I enter a numeric value into the field, the translator returns
> a Long, and I get a class cast exception when try to set it to a value.
> 
>  <at> Parameter(defaultValue = "translator:number")
> public abstract Translator getTranslator();
> 
> InjectObject("service:tapestry.form.TranslatedFieldSupport")
> public abstract TranslatedFieldSupport getTranslatedFieldSupport();
> 
> Integer dayInt = (Integer) getTranslatedFieldSupport().parse(this,
> dayValue);

Try:

Integer dayInt = 
  new Integer(
    ((Number) getTranslatedFieldSupport().parse(this, dayValue)).intValue());

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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