Looks ok to me altho im not familiar with parse position
You might wanna allow blank too
if (price != null && price.trim().length() != 0) {
And catch NumberFormatException / set an error
And setPriceDouble(null) in your forms reset() method
Peter Neu wrote:
OK so what I did is:
--jsp---
<input name="price" value="<bean:write name="Obj" property="price"
format="##"/>" />
-> Value gets displayed with commas.
--action-form-
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.GERMAN);
DecimalFormat df = (DecimalFormat) nf;
df.setDecimalSeparatorAlwaysShown(false);
df.applyPattern("#,###,###,###,###.#########");
if (price != null) {
if (price.contains(".")) {
ActionError msg = new
ActionError("servlets.jsp.error.edit1");
errors.add("uploadErr", msg);
System.out.println("error");
} else {
ParsePosition pp2 = new ParsePosition(0);
Number inNbr = df.parse(price, pp2);
setPriceDouble(inNbr.doubleValue());
}
}
In my struts action form I check for null values and the copy the string
representation into a double value.
Does that make sense?
-----Ursprüngliche Nachricht-----
Von: Lance [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 16. April 2007 11:31
An: Struts Users Mailing List
Betreff: Re: AW: AW: HowTo Format Numbers in html:text tag?
Your brute force approach does not use <html:text /> tho?
Also, I have a suspicion that struts will either throw an exception or
set nulls for inputted numbers that contain commas, you might need to
use Strings on your form and format / parse to numbers in your action(s).
Peter Neu wrote:
But that's more code than the brute force approach:
<input name="usage" value="<bean:write name="Obj" property="usage"
format="##"/>" />
If have about 20-30 items. :o(
-----Ursprüngliche Nachricht-----
Von: Lance [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 16. April 2007 11:05
An: Struts Users Mailing List
Betreff: Re: AW: HowTo Format Numbers in html:text tag?
You could combine with struts-el
<!-- store in formattedNumber (don't output -->
<fmt:formatDate value="${myForm.myNumber}" pattern="??"
var="formattedNumber" />
<!-- use the formatted value -->
<html-el:text property="myNumber" value="${formattedNumber}" />
Peter Neu wrote:
That looks cool but I need to embed the value in the html:text field
so
the
user is able to edit the value. That won't work with 2 tags. :o(
-----Ursprüngliche Nachricht-----
Von: Lance [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 16. April 2007 10:45
An: Struts Users Mailing List
Betreff: Re: HowTo Format Numbers in html:text tag?
You could use <fmt:formatDate /> in JSTL
http://bellsouthpwp.net/b/i/billsigg/jstl-quick-reference.pdf
<http://bellsouthpwp.net/b/i/billsigg/jstl-quick-reference.pdf>
Peter Neu wrote:
Hello,
I need to format a number string in a html:text tag because the
default
value must be written with a comma sperator. e.g. 4,5 while the
value
of
my
value bean is in fact like this: 4.5.
Normally I would use bean:message and the format attribute. But this
does
not work in html:text.
How can I do this?
Cheers,
Pete
--------------------------------------------------------------------
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]