Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default value=0 of int field changing in form struts

 
Dattatray Sutar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic