aspose file tools*
The moose likes Struts and the fly likes using same form for all my actions 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 » Frameworks » Struts
Bookmark "using same form for all my actions" Watch "using same form for all my actions" New topic
Author

using same form for all my actions

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hi all,

I am using only one formbean for all my actions and jsps. And my doubt is that if i set some value from lets say first action and i want to get the that value prited in say 5th jsp. can i use that?

And can anyone please tell me how often my form get reset in my module. in other words without calleing the reset method declared in the formbean can anything reset all vallues to null or something?

And same question can be asked how much time values set in the formbean can live?

thanks in advance.. im very sorry if you fell bored of reading this question but i think, this is very intresting and usefull to all

reagrds,

rahul.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Rauhl Roy:
I am using only one formbean for all my actions and jsps.

Why are you doing this? Struts was designed around the model of there being a one-to-one relationship between an ActionForm and a JSP. I don't see any advantage of shoving all fields from all JSPs into a single form bean, and I see lots of disadvantages, particularly when it comes to validation.

The only time I could see doing this would be in a "wizard" type situation where you have multiple pages entering data and at the end of the wizard, the user saves the data entered from all pages.
Originally posted by Rauhl Roy:
And can anyone please tell me how often my form get reset in my module. in other words without calleing the reset method declared in the formbean can anything reset all vallues to null or something?

Struts calls the reset method on an ActionForm every time a form is submitted. If you don't override the reset method or put any logic in it, nothing happens.
Originally posted by Rauhl Roy:
how much time values set in the formbean can live?

They live as long as the scope you specify. If you specify a scope of request, they live for one request. If you specify a scope of session, they live as long as the current user is signed on.
[ June 27, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

yes Mr. Merrill Higginson , I am using wizard kind of stuff where i have to get the values from 2 jsps then i have to show to user in tht 3rd page as a summary after taking the confirmation from him i have to save in back end system.

the answer's question..can not we get same advantages when I use the one-to-one relation ship model formbean?

And 3rd one is, did you mean, we have to call the reset method from the Action bean otherwise nothing is changed.

thanks in advance.
Regards,
rahul.
Abhilash George
Greenhorn

Joined: Apr 28, 2006
Posts: 13
a) See the default scope of any formbean is session . So the contents of the form would be available in your session as long as you want them. This means that you could have two different forms for different jsp and in the end create a third formbean and fill it with data from the first two.
But as it is its not a good idea keeping the whole form in a session so you can keep the form in request , and on submit push those values into a Value object which has been kept in session and use it to populate the third page formbean

b) if the form is in request scope it will go anyways with a submit but if in session then you mite need to call reset to clear things you want


george
Abhilash George
Greenhorn

Joined: Apr 28, 2006
Posts: 13
a) See the default scope of any formbean is session . So the contents of the form would be available in your session as long as you want them. This means that you could have two different forms for different jsp and in the end create a third formbean and fill it with data from the first two.
But as it is its not a good idea keeping the whole form in a session so you can keep the form in request , and on submit push those values into a Value object which has been kept in session and use it to populate the third page formbean

b) if the form is in request scope it will go anyways with a submit but if in session then you might need to call reset to clear things you want
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using same form for all my actions