aspose file tools*
The moose likes Struts and the fly likes Should we use ActionForms on the way back? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Should we use ActionForms on the way back?" Watch "Should we use ActionForms on the way back?" New topic
Author

Should we use ActionForms on the way back?

Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi,
at the beginning of my Struts studies i had the following notion on how to use the ActionForms.

Data in ...
JSP -> ActionForm -> Action -> Session Fa�ade -> Domain model
Data out ...
Domain model -> Session Fa�ade -> Action -> JSP

In other words, from a Action a access the fa�ade and, if everything goes ok, i forward my data to a JSP.

Tough, i have heard that on the way back we should also use the ActionForm, making something like this.
Data in...
JSP -> ActionForm -> Action -> Session Fa�ade -> Domain model
Data out ... NOW THE DIFFERENCE
Domain model -> Session Fa�ade -> Action -> ACTION FORM -> JSP

Can any one give me a overview on that???


Leandro Melo
SCJP 1.4, SCWCD 1.4
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

A lot of times you can use an ActionForm before a page gets displayed to fill in the Form with default values. DynaActionForm also allows you to define default values into the Form fields.

Oh, I forgot, this also helps if the user hits the back button, then the Form can keep the values that they had origanlly entered, because the reset() method won't rerun in the case of a user hitting the back button.

Unfortunately, you could use the ActionForm to hold the data that comes back, but I think that is using the ActionForm to do something that is shouldn't be used for. For those that need the data returned, it is best to put them into DTO (Data Transfer Objects) or VO (Value Objects), both are the same thing, it just depends on what you call them. I called them VOs, but my work uses the DTO, but they are the same thing.

Mark
[ June 06, 2004: Message edited by: Mark Spritzler ]

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Originally posted by Mark Spritzler:
Unfortunately, you could use the ActionForm to hold the data that comes back, but I think that is using the ActionForm to do something that is shouldn't be used for.
So, do you recommend not using ActionForm for prepopulating values? I'm also facing a similar dilemma as described above.

I have a highly input intensive forms as requirement and I need to retain/allow editing the data across sessions. Currently I'm using VOs as instance variables of the ActionForm.

Please shed some more light on this.

Thanks and regards,
Kinjal Sonpal
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Originally posted by Kinjal Sonpal:
So, do you recommend not using ActionForm for prepopulating values?Kinjal Sonpal


No that is NOT what I am saying.

Using them to prepopulate is OK. Using the ActionForm to hold data that comes back that you want to do some processing on is what you should avoid, when using ActionForm classes. Obviously, in my opinion. I think that is what VO objects and Plain Old Java Objects (POJO) should be used for.

Mark
Dave Knipp
Ranch Hand

Joined: Oct 14, 2003
Posts: 146
I agree with Mark, the only data you should pre-populate your form with is the data that needs to be displayed. But you should use actionforms to display the data on your page, b/c it will keep your design consistent and makes the struts tags easier to use.


SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Thanks a lot for sharing your views on this. I'll keep those thumb-rules in mind.

Thanks and regards,
Kinjal Sonpal
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
So, after all this discussion i understant that it`s ok to use the ActioForm to pre-poluate my page (if there`s no processing on the data) on the way back from a session fa�ade, for example.

Then, in this case, we would have 2 ActionForms for somekinda action rigth?!
For example?
- JSP1: User inputs data for registering his address, data goes to model through the ActionForm1.
- Business logic...
- JSP2: User views the data he entered (in labels for example) through an ActionForm2 pre-polulating this page with all the same data his entered.

I hope i got it right, but then my question is:
The data i show in JSP2 should come from a "select" (to the session fa�ade) of the data just enter by the user, or the data displayed in JSP2 should be the exact same instances that the ones the user entered (in this case, i would not make a select of the data just inserted and just use the data in the input ActionForm)???
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Actually with what you just described... if jsp2 does not contain any other input values (or values in addition to those from jsp1), then just use the same ActionForm in your ActionMappings for jsp1 and jsp2.

You would not even not to worry about prepopulation of jsp2 in this scenario - it magically stays right there for you.
[ June 08, 2004: Message edited by: Marc Peabody ]

A good workman is known by his tools.
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Originally posted by Marc Peabody:
You would not even not to worry about prepopulation of jsp2 in this scenario - it magically stays right there for you.
Will it stay across request, even if the scope attribute of the action tag says request? I thought the ActionForm would be out of scope. I've always been using session scope for such situations and would use session clean-up later. I'm also assuming that the name attribute of both the actions would be the same as that of the concerned form-bean tag.

I would have tried this out myself, but I'm not around my machine. Please shed some more light on this.

Thanks and regards,
Kinjal Sonpal
[ June 08, 2004: Message edited by: Kinjal Sonpal ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should we use ActionForms on the way back?