File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts Form Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Form Bean" Watch "Struts Form Bean" New topic
Author

Struts Form Bean

dnyan ginde
Ranch Hand

Joined: Jan 17, 2006
Posts: 68
Is it necessary that the properties of a form bean be of the type String? What happens if I use integer or float or for that matter anything other than String? I tried using integer and it worked fine but Ive read in quite a few books and articles that the properties of a form bean must be String. What problems can i face if i use anything other than String? Is there an explanatory answer to "why use String"?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The biggest problem with using non-Strings in an ActionForm is with validation. Let's say you have an html:text tag on your JSP and the property is an integer. What happens if the user enters something other than a valid integer in that field? When Struts executes the setter for that field, it will throw a number Format exception. Even if you have server-side validation logic to check the field, When Struts redisplays the page, the field will show zero instead of the invalid data the user actually entered.

If you have a field that is read-only, then I see no problem with declaring it as a non-String in the ActionForm. You can even format it using the format property of bean:write.


Merrill
Consultant, Sima Solutions
dnyan ginde
Ranch Hand

Joined: Jan 17, 2006
Posts: 68
Thanks a lot Merrill...
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Hi,

Good info Merrill.

Bye,
Viki.


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
 
 
subject: Struts Form Bean