You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alberto Lepe <al...@gmail.com> on 2005/03/02 21:00:16 UTC

Newbie - Double or Float casting

(I don't like to ask questions other people already did, but Search in
Mailing List is still down :(  )
I'm trying to implement a Currency example by my own.  I think I read
tapestry cast all Java type when the form is submited. For example:
(In this example the result is displayed in the same TextField)
--------------------------------------------------------------------------------
In my Home.page:
--------------------------------------------------------------------------------
<page-specification class="classes.Currency">
<property-specification name="currency" type="java.lang.Double"/>
<component id="FormCurrency" type="Form">
	<binding name="listener" expression="listeners.transformCurrency" />
</component>
<component id="currencyField" type="TextField">
		<binding name="value" expression="currency" />
</component>
...
--------------------------------------------------------------------------------
In my Currency.java:
--------------------------------------------------------------------------------
public abstract class Currency extends BasePage {
	public abstract Double getCurrency();
	public abstract void   setCurrency(Double result);

	public void transformCurrency (IRequestCycle cycle){
		setCurrency(getCurrency()*1.35);
		return;
	}
}
--------------------------------------------------------------------------------
It display an error like:

" Parameter value (13.50) is an instance of java.lang.Double, which
does not inherit from java.lang.String. "

I thought tapestry transform the type in both ways: 
when the form is submited and when the information is displayed.

I'm right? or do I have to cast the variable manually?
Thank you.

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


Re: Newbie - Double or Float casting

Posted by Danny Mandel <dm...@tolweb.org>.
Right now, the only officially supported way to make a TextField bind to 
a Double value is through the use of ValidField:

http://jakarta.apache.org/tapestry/doc/ComponentReference/ValidField.html

Combined with a NumberValidator 
(http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/valid/NumberValidator.html), 
you can directly bind a ValidField to your Double type.

Of course, you could bind the field value to something that translates 
your String to a Double or any other number of custom solutions, but the 
ValidField is the standard framework way to do it.

Hope that helps,
Danny

Alberto Lepe wrote:

>(I don't like to ask questions other people already did, but Search in
>Mailing List is still down :(  )
>I'm trying to implement a Currency example by my own.  I think I read
>tapestry cast all Java type when the form is submited. For example:
>(In this example the result is displayed in the same TextField)
>--------------------------------------------------------------------------------
>In my Home.page:
>--------------------------------------------------------------------------------
><page-specification class="classes.Currency">
><property-specification name="currency" type="java.lang.Double"/>
><component id="FormCurrency" type="Form">
>	<binding name="listener" expression="listeners.transformCurrency" />
></component>
><component id="currencyField" type="TextField">
>		<binding name="value" expression="currency" />
></component>
>...
>--------------------------------------------------------------------------------
>In my Currency.java:
>--------------------------------------------------------------------------------
>public abstract class Currency extends BasePage {
>	public abstract Double getCurrency();
>	public abstract void   setCurrency(Double result);
>
>	public void transformCurrency (IRequestCycle cycle){
>		setCurrency(getCurrency()*1.35);
>		return;
>	}
>}
>--------------------------------------------------------------------------------
>It display an error like:
>
>" Parameter value (13.50) is an instance of java.lang.Double, which
>does not inherit from java.lang.String. "
>
>I thought tapestry transform the type in both ways: 
>when the form is submited and when the information is displayed.
>
>I'm right? or do I have to cast the variable manually?
>Thank you.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>  
>


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