You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paolo Niccolò Giubelli <pa...@itestense.it> on 2009/01/30 19:53:45 UTC
textbox showing currency default value
Hi! I need to display a textbox, where the user should write a money
value in eur. I need the textbox to display the default value in the
correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
Of course, the textbox is "connected" with a float field. Now I get 0.0
as the default value and when I type something like 20,99 the value is
not recognized as a valid float.
Any idea? Thank you in advance!
Paolo
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by Paweł Wielgus <po...@gmail.com>.
Hi Paolo,
first of all float for cash is a very bad idea. Use BigDecimal.
Then You can ass getter and setter in Form like this:
public String getMyFieldValue() {
return myFieldValue.toString().replaceAll(".", ",");
}
public void setMyFieldValue(String amount) {
myFieldValue = new BigDecimal(amount.replaceAll(",", "."));
}
where myFieldValue is a BigDecimal field in Your form.
You could also use some kind of NumberFormat or something if You like.
Best greetings,
Paweł Wielgus.
2009/1/31 Paolo Niccolò Giubelli <pa...@itestense.it>:
> This is my idea: jsp should convert my float value to a String so to display
> it in my textbox. I suppose jsp uses a subclass of NumberFormat to do so...
> may I change this behaviour so to use DecimalFormat.getCurrencyFormat()?
> Thank you in advance...
> Paolo
>
> Paolo Niccolò Giubelli ha scritto:
>>
>> There's no method in the Action class returning a String. Can you help me?
>> Thank you so much,
>> Paolo
>> Zheng, Qiang ha scritto:
>>>
>>> You need to implement that in action.
>>>
>>> -----Original Message-----
>>> From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
>>> Sent: Friday, January 30, 2009 2:26 PM
>>> To: Struts Users Mailing List
>>> Subject: Re: textbox showing currency default value
>>>
>>> sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
>>>
>>> Paolo Niccolò Giubelli ha scritto:
>>>>
>>>> Sorry, I don't understand from where I should return what.
>>>> I have a Form with a float m_price = 0.0 field (wit accessors methods).
>>>> In the jsp I have
>>>>
>>>> <html:text name="m_price" />
>>>>
>>>> I need to se a textbox like this
>>>>
>>>> |--------------------|
>>>> | 0,00 |
>>>> |--------------------|
>>>>
>>>>
>>>> Thanks anyway.
>>>>
>>>> Zheng, Qiang ha scritto:
>>>>>
>>>>> You can try load the locale of this user and
>>>>>
>>>>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>>>>> Return currencyformat.format(amount);
>>>>>
>>>>> -----Original Message-----
>>>>> From: Paolo Niccolò Giubelli
>>>>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30, 2009
>>>>> 1:54 PM
>>>>> To: Struts Users Mailing List
>>>>> Subject: textbox showing currency default value
>>>>>
>>>>> Hi! I need to display a textbox, where the user should write a money
>>>>> value in eur. I need the textbox to display the default value in the correct
>>>>> currency mode, like 0,00 (comma separated decimals) and not 0.0.
>>>>> Of course, the textbox is "connected" with a float field. Now I get 0.0
>>>>> as the default value and when I type something like 20,99 the value is not
>>>>> recognized as a valid float.
>>>>> Any idea? Thank you in advance!
>>>>> Paolo
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by Paolo Niccolò Giubelli <pa...@itestense.it>.
This is my idea: jsp should convert my float value to a String so to
display it in my textbox. I suppose jsp uses a subclass of NumberFormat
to do so... may I change this behaviour so to use
DecimalFormat.getCurrencyFormat()?
Thank you in advance...
Paolo
Paolo Niccolò Giubelli ha scritto:
> There's no method in the Action class returning a String. Can you help me?
> Thank you so much,
> Paolo
> Zheng, Qiang ha scritto:
>> You need to implement that in action.
>>
>> -----Original Message-----
>> From: Paolo Niccolò Giubelli
>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30,
>> 2009 2:26 PM
>> To: Struts Users Mailing List
>> Subject: Re: textbox showing currency default value
>>
>> sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
>>
>> Paolo Niccolò Giubelli ha scritto:
>>> Sorry, I don't understand from where I should return what.
>>> I have a Form with a float m_price = 0.0 field (wit accessors methods).
>>> In the jsp I have
>>>
>>> <html:text name="m_price" />
>>>
>>> I need to se a textbox like this
>>>
>>> |--------------------|
>>> | 0,00 |
>>> |--------------------|
>>>
>>>
>>> Thanks anyway.
>>>
>>> Zheng, Qiang ha scritto:
>>>> You can try load the locale of this user and
>>>>
>>>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>>>> Return currencyformat.format(amount);
>>>>
>>>> -----Original Message-----
>>>> From: Paolo Niccolò Giubelli
>>>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January
>>>> 30, 2009 1:54 PM
>>>> To: Struts Users Mailing List
>>>> Subject: textbox showing currency default value
>>>>
>>>> Hi! I need to display a textbox, where the user should write a money
>>>> value in eur. I need the textbox to display the default value in the
>>>> correct currency mode, like 0,00 (comma separated decimals) and not
>>>> 0.0.
>>>> Of course, the textbox is "connected" with a float field. Now I get
>>>> 0.0 as the default value and when I type something like 20,99 the
>>>> value is not recognized as a valid float.
>>>> Any idea? Thank you in advance!
>>>> Paolo
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by QZ <qz...@servicebench.com>.
You can add this to your action, locale needs to come from user,
public String getCurrency(float amount) {
Format currencyformat = NumberFormat.getCurrencyInstance(locale);
Return currencyformat.format(amount);
}
Paolo Niccolò Giubelli-2 wrote:
>
> There's no method in the Action class returning a String. Can you help me?
> Thank you so much,
> Paolo
> Zheng, Qiang ha scritto:
>> You need to implement that in action.
>>
>> -----Original Message-----
>> From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
>> Sent: Friday, January 30, 2009 2:26 PM
>> To: Struts Users Mailing List
>> Subject: Re: textbox showing currency default value
>>
>> sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
>>
>> Paolo Niccolò Giubelli ha scritto:
>>> Sorry, I don't understand from where I should return what.
>>> I have a Form with a float m_price = 0.0 field (wit accessors methods).
>>> In the jsp I have
>>>
>>> <html:text name="m_price" />
>>>
>>> I need to se a textbox like this
>>>
>>> |--------------------|
>>> | 0,00 |
>>> |--------------------|
>>>
>>>
>>> Thanks anyway.
>>>
>>> Zheng, Qiang ha scritto:
>>>> You can try load the locale of this user and
>>>>
>>>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>>>> Return currencyformat.format(amount);
>>>>
>>>> -----Original Message-----
>>>> From: Paolo Niccolò Giubelli
>>>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30,
>>>> 2009 1:54 PM
>>>> To: Struts Users Mailing List
>>>> Subject: textbox showing currency default value
>>>>
>>>> Hi! I need to display a textbox, where the user should write a money
>>>> value in eur. I need the textbox to display the default value in the
>>>> correct currency mode, like 0,00 (comma separated decimals) and not
>>>> 0.0.
>>>> Of course, the textbox is "connected" with a float field. Now I get
>>>> 0.0 as the default value and when I type something like 20,99 the
>>>> value is not recognized as a valid float.
>>>> Any idea? Thank you in advance!
>>>> Paolo
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/textbox-showing-currency-default-value-tp21753399p21831862.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by Paolo Niccolò Giubelli <pa...@itestense.it>.
There's no method in the Action class returning a String. Can you help me?
Thank you so much,
Paolo
Zheng, Qiang ha scritto:
> You need to implement that in action.
>
> -----Original Message-----
> From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
> Sent: Friday, January 30, 2009 2:26 PM
> To: Struts Users Mailing List
> Subject: Re: textbox showing currency default value
>
> sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
>
> Paolo Niccolò Giubelli ha scritto:
>> Sorry, I don't understand from where I should return what.
>> I have a Form with a float m_price = 0.0 field (wit accessors methods).
>> In the jsp I have
>>
>> <html:text name="m_price" />
>>
>> I need to se a textbox like this
>>
>> |--------------------|
>> | 0,00 |
>> |--------------------|
>>
>>
>> Thanks anyway.
>>
>> Zheng, Qiang ha scritto:
>>> You can try load the locale of this user and
>>>
>>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>>> Return currencyformat.format(amount);
>>>
>>> -----Original Message-----
>>> From: Paolo Niccolò Giubelli
>>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30,
>>> 2009 1:54 PM
>>> To: Struts Users Mailing List
>>> Subject: textbox showing currency default value
>>>
>>> Hi! I need to display a textbox, where the user should write a money
>>> value in eur. I need the textbox to display the default value in the
>>> correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
>>> Of course, the textbox is "connected" with a float field. Now I get
>>> 0.0 as the default value and when I type something like 20,99 the
>>> value is not recognized as a valid float.
>>> Any idea? Thank you in advance!
>>> Paolo
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: textbox showing currency default value
Posted by "Zheng, Qiang" <qz...@Servicebench.com>.
You need to implement that in action.
-----Original Message-----
From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
Sent: Friday, January 30, 2009 2:26 PM
To: Struts Users Mailing List
Subject: Re: textbox showing currency default value
sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
Paolo Niccolò Giubelli ha scritto:
> Sorry, I don't understand from where I should return what.
> I have a Form with a float m_price = 0.0 field (wit accessors methods).
> In the jsp I have
>
> <html:text name="m_price" />
>
> I need to se a textbox like this
>
> |--------------------|
> | 0,00 |
> |--------------------|
>
>
> Thanks anyway.
>
> Zheng, Qiang ha scritto:
>> You can try load the locale of this user and
>>
>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>> Return currencyformat.format(amount);
>>
>> -----Original Message-----
>> From: Paolo Niccolò Giubelli
>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30,
>> 2009 1:54 PM
>> To: Struts Users Mailing List
>> Subject: textbox showing currency default value
>>
>> Hi! I need to display a textbox, where the user should write a money
>> value in eur. I need the textbox to display the default value in the
>> correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
>> Of course, the textbox is "connected" with a float field. Now I get
>> 0.0 as the default value and when I type something like 20,99 the
>> value is not recognized as a valid float.
>> Any idea? Thank you in advance!
>> Paolo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by Paolo Niccolò Giubelli <pa...@itestense.it>.
sorry... I meant <html:text property="m_price"/>.. I'm really tired...:D
Paolo Niccolò Giubelli ha scritto:
> Sorry, I don't understand from where I should return what.
> I have a Form with a float m_price = 0.0 field (wit accessors methods).
> In the jsp I have
>
> <html:text name="m_price" />
>
> I need to se a textbox like this
>
> |--------------------|
> | 0,00 |
> |--------------------|
>
>
> Thanks anyway.
>
> Zheng, Qiang ha scritto:
>> You can try load the locale of this user and
>>
>> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
>> Return currencyformat.format(amount);
>>
>> -----Original Message-----
>> From: Paolo Niccolò Giubelli
>> [mailto:paoloniccolo.giubelli@itestense.it] Sent: Friday, January 30,
>> 2009 1:54 PM
>> To: Struts Users Mailing List
>> Subject: textbox showing currency default value
>>
>> Hi! I need to display a textbox, where the user should write a money
>> value in eur. I need the textbox to display the default value in the
>> correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
>> Of course, the textbox is "connected" with a float field. Now I get
>> 0.0 as the default value and when I type something like 20,99 the
>> value is not recognized as a valid float.
>> Any idea? Thank you in advance!
>> Paolo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: textbox showing currency default value
Posted by Paolo Niccolò Giubelli <pa...@itestense.it>.
Sorry, I don't understand from where I should return what.
I have a Form with a float m_price = 0.0 field (wit accessors methods).
In the jsp I have
<html:text name="m_price" />
I need to se a textbox like this
|--------------------|
| 0,00 |
|--------------------|
Thanks anyway.
Zheng, Qiang ha scritto:
> You can try load the locale of this user and
>
> Format currencyformat = NumberFormat.getCurrencyInstance(locale);
> Return currencyformat.format(amount);
>
> -----Original Message-----
> From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
> Sent: Friday, January 30, 2009 1:54 PM
> To: Struts Users Mailing List
> Subject: textbox showing currency default value
>
> Hi! I need to display a textbox, where the user should write a money
> value in eur. I need the textbox to display the default value in the
> correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
> Of course, the textbox is "connected" with a float field. Now I get 0.0
> as the default value and when I type something like 20,99 the value is
> not recognized as a valid float.
> Any idea? Thank you in advance!
> Paolo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: textbox showing currency default value
Posted by "Zheng, Qiang" <qz...@Servicebench.com>.
You can try load the locale of this user and
Format currencyformat = NumberFormat.getCurrencyInstance(locale);
Return currencyformat.format(amount);
-----Original Message-----
From: Paolo Niccolò Giubelli [mailto:paoloniccolo.giubelli@itestense.it]
Sent: Friday, January 30, 2009 1:54 PM
To: Struts Users Mailing List
Subject: textbox showing currency default value
Hi! I need to display a textbox, where the user should write a money
value in eur. I need the textbox to display the default value in the
correct currency mode, like 0,00 (comma separated decimals) and not 0.0.
Of course, the textbox is "connected" with a float field. Now I get 0.0
as the default value and when I type something like 20,99 the value is
not recognized as a valid float.
Any idea? Thank you in advance!
Paolo
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org