• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading multiple forms in single jsp

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My jsp page has multiple forms (one form for each table which has specific info). So assume it has 3 tables, so 3 forms.

I need to load all the form when the page is loaded.



So if I need to load all the forms, how should I proceed. Also please note each form has its own form class and action class.

Any help would be greatly appreciated.

Thanks.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks
[ February 07, 2007: Message edited by: vjy chin ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

- Brent
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brent,

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.

Thanks for your time.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you please explain how you have done it.
I am having a page. I need to load data from database when the page loads.
how can we do it..
please help its urgent
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic