File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes (Struts) Any class that can do introspection for me? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "(Struts) Any class that can do introspection for me?" Watch "(Struts) Any class that can do introspection for me?" New topic
Author

(Struts) Any class that can do introspection for me?

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4702
    
    7

I am currently developing an application using Struts. I have chosen to move the data from my ActionForm to a DataObject. This has worked pretty well so far because data that must be saved at the same time can come from multiple data entry screens. With the DataObject, I can just stuff values from the ActionForm and pass the DataObject around until it is time to save it. It has also helped me keep the API to the persistence layer relatively simple as I usually just pass a DataObject to/from it.
Each of my ActionForm classes has a copyTo(DataObject) and copyFrom(DataObject) method. The methods basically do what Struts does with the JSP/request and the ActionForm: moves values of attributes between the two.
Questions:
1. What do you think of the approach I am using?
2. Are there any issues that I may encounter later by using this approach?
3. I am currently manually copying fields to and from the ActionForm and DataObject. This is getting more unwieldy as I add more fields to the ActionForm and DataObject. Is there a way to automate this process without having to write my own reflection-based utility class? That is, is there a class/method in Struts that can do this? (I could dig around the Struts source and see for myself but if anyone knows offhand, it would save me some time and effort )
TIA!
Junilu
[This message has been edited by JUNILU LACAR (edited November 03, 2001).]


Junilu - [How to Ask Questions] [How to Answer Questions]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by JUNILU LACAR:
I am currently developing an application using Struts. I have chosen to move the data from my ActionForm to a DataObject. This has worked pretty well so far because data that must be saved at the same time can come from multiple data entry screens. With the DataObject, I can just stuff values from the ActionForm and pass the DataObject around until it is time to save it. It has also helped me keep the API to the persistence layer relatively simple as I usually just pass a DataObject to/from it.
Each of my ActionForm classes has a copyTo(DataObject) and copyFrom(DataObject) method. The methods basically do what Struts does with the JSP/request and the ActionForm: moves values of attributes between the two.
Questions:
1. What do you think of the approach I am using?
2. Are there any issues that I may encounter later by using this approach?
3. I am currently manually copying fields to and from the ActionForm and DataObject. This is getting more unwieldy as I add more fields to the ActionForm and DataObject. Is there a way to automate this process without having to write my own reflection-based utility class? That is, is there a class/method in Struts that can do this? (I could dig around the Struts source and see for myself but if anyone knows offhand, it would save me some time and effort )
TIA!
Junilu
[This message has been edited by JUNILU LACAR (edited November 03, 2001).]


Hi Junilu. I think your approach is fine -- it's exactly what I've done in my own struts code and in the articles on struts that I wrote.
I don't think there's anything in struts like you describe. Sounds like you're going to have to write a utility class to me...
Kyle

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (Struts) Any class that can do introspection for me?