wood burning stoves 2.0*
The moose likes Struts and the fly likes default value=0 of int field changing in form struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "default value=0 of int field changing in form struts" Watch "default value=0 of int field changing in form struts" New topic
Author

default value=0 of int field changing in form struts

Dattatray Sutar
Ranch Hand

Joined: Jul 12, 2006
Posts: 46
hi all

why certain fields of form int or float datatype have there default value set as 0 every time i access the jsp page.
Can we change this .i.e. i want nothing in place of default 0 appearing in int datatype form field.

Thanks in advance


with regards<br />Datta.<br /> <br />To the world you might be one person, but to one person you just might be the world !
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Even for numeric fields, it's best to define them as Strings in your ActionForm bean. One of the reasons for doing this is the problem you mention: the fact that they show as "0" rather than blank on the form. Another reason is validation. If the user enters a non-numeric value, Struts will throw a NumberFormatException when it tries to populate the form.

It's fine to represent the value as numeric in your model classes, but validate it first and then convert it to numeric.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default value=0 of int field changing in form struts