Originally posted by vjy chin: I need to load all the form when the page is loaded.
If by "loaded" you mean the data in the forms populated by ActionForm beans, then you don't need to do anything at all to make this happen. All the data in all the forms will be loaded when the page is displayed. Struts and the web container will handle this automatically.
If you need to populate multiple ActionForm beans prior to displaying the page, you can do so. Just instantiate the beans, populate them, and put them in the proper scope. So, for example, if you specified request scope for each action mapping, you could do the following:
However, you need to understand that when the user presses a submit button, only the form that encloses that particular submit button will be submitted. The other two will not. [ February 06, 2007: Message edited by: Merrill Higginson ]
I am not in my office now, so will try out your suggestion tomorrow.
By loading I meant, populating the table values from database. So I can call a service class in the reset method of each form, populate each bean and set it in the request. AM I right?
I will try out and let you know tomorrow.
Thanks for the suggestion.
Joined: Feb 15, 2005
Yes, you could populate each Form in the reset() method and it would work. This solution does present problems, though. Struts will call the reset method before displaying the JSP, which is great, but when the form is submitted, Struts will call the reset() method again, which in your example will result in unnecessary database access.
I think it's cleaner to create a preparatory action that loads all the forms and then forwards to the JSP. That way you are in complete control of when the database access code is called and when it isn't.
Joined: Feb 17, 2005
Thanks For the reply again. But can you explain this a bit more
I think it's cleaner to create a preparatory action that loads all the forms and then forwards to the JSP
How can I call an action without any events? I mean
For e.g. Assume Page A (From Page A I am coming to this form page via a hyperlink and there is no action class in between) calls the page with 3 forms and I need to display all the values in the 3 forms. So how can I call the action classes for each of the 3 forms.
So when and how will the action1, action2, action3 called?
From Page A I am coming to this form page via a hyperlink and there is no action class in between
Well there is your answer...you need an action class in between! Rather than having a hyperlink directly to a JSP, you would use a hyperlink to an action. This action would be responsible for instantiating, populating and saving to the request (or session) all three action forms. In general I like to think that every JSP file needs two actions...one to display the page and one to process the submission of the page.
Joined: Feb 17, 2005
I was also thinking of the same, using an action class in between, but in the requirement doc, it was given as normal hyperlink. So got that sorted out now.
Using action class in between i am able to load the data.