This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IndexedProperties doubt

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ram Gokul
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. ?

Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic