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

IndexedProperties doubt

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

I have a ArrayList which has a bunch of DTO objects.

Following are the attributes in the DTO object.

1. String empName;
2. Integer empNumber;
3. java.util.Date doj;

I am iterating the arraylist in the jsp using logic:iterate and using bean:write, just to display the values in a table.

Is there any problem with the data types in the DTO object. Will this work, since the DTO doesn't have simple String objects.

I am just displaying the values in a table.

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Vishnu Prakash:
Is there any problem with the data types in the DTO object.

There's no problem with the data types as long as you're just displaying the values. It's only when you're creating input controls for these values that you would run into problems with non-String properties.

Consultant, Sima Solutions
Ram Gokul
Ranch Hand

Joined: Oct 07, 2005
Posts: 85
what problems will we run into ? ( I am using indexed properties for first time ...)

In my grid ( which is editable ), my objects contain some int . Will Struts convert it into String before displaying and convert it back to int ? or should I convert into String and take care of int conversion in my Model class. ?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Struts will handle the conversion to and from int, but I still don't think it's a good idea to use it here. Struts will not handle the object wrapper Integer, or any other objects such as java.util.Date.

Here are reasons why it's not a good idea. The first is that uninitialized values will show as "0" instead of blank. Another is that if the user enters a non-numeric value in the field, Struts will throw a NumberFormatException. It's better to define the fields as String in the ActionForm and its contained objects and convert them to other data types later if you need to.

This is one area where Struts 1 is showing its age. Newer frameworks such as JSF and Struts 2 do handle data conversions and provide friendly error messages when the conversion fails.
[ July 31, 2007: Message edited by: Merrill Higginson ]
I agree. Here's the link:
subject: IndexedProperties doubt
jQuery in Action, 3rd edition