• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IntegerConverter converts empty string to 0

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We have a struts application which was recently migrated to 1.2.8 from 1.0. ActionForms in our app have value objects that contain Integer objects. These are getting initialized to 0 by struts framework at the time of submitting a form. org.apache.commons.beanutils.converters.IntegerConverter seems to be the culprit. We want the un-initialized Integer objects to remain null. Has anybody encountered a similar issue and do we have a workaround available. It seem custom converters can do the job for us. However, when beantutils are separetely used then it can be easily done, but when it's called from struts, then it may not be that easy. I need your help in sorting out this issue.

Thanks a lot.
Tauqueer.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One solution would be to create a second getter/setter pair for the property (e.g. getQtyAsString/setQtyAsString) that treat it as a String and then convert it to and from an integer. Then in your JSP, you'd write <html:text property="qtyAsString" />. That way struts will treat it as a String and not try to put zeroes into it. If you look at the documentation, the authors of Struts have always urged us to use Strings as properties in ActionForm beans.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic