• 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

Struts 1 :- Two Form submission from one jsp using one submit button

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, this is my 1st post...

I am facing problem in submitting two forms from one JSP on one submit button..
I am using Struts 1.1, MySql 5.1 and Tomcat 6.20
Here is the detailed senario...

1. I have 2 tables Warehouse and Address in my MySql db,
2 . Warehouse table has address_id field as a foreign key which is a Auto_increment value in address table
3. I have a jsp called createWarehouse.jsp which contains two forms for warehouse and address with one submit button in address form,
4. I use a javascript to submit these two forms
5. As address id is the foreign key i need to persist address details 1st, so i set the action for address form and submit it through javascript
6. Then i take the address_id put it in a session object and refer it while persisting warehouse details.
7. Then from the same js function i submit warehouse form too
8. Every thing goes fine if i put a alert() statement between two form submissions
9. But if i remove that alert statement only address gets persisted

Here is wht i have figured out : In case if i don't put the alert statement in between.
1. When address form is submitted it goes to actionclass then to the daobean class and the queries are executed there,
2. But simultaneously the control goes forward in jsp file it goes to submit the warehouse form, this both process are going on parallely
3. And as in warehouse action it doesn't get the address_id from session it doesn't persist in warehouse table

But if i put the alert statement there is a pause between two submission and the address form submission gets enough time to get session object containing address_id.

I don't want to use window.timeout() as the transaction time can vary, even tried to put a while loop until i get the session attribute but dint work
Are my finding correct ???....
Please tell me a way around....Hoping to hear from Experts


Code is given below:--

JavaScript:-


createWarehouse.jsp :-


struts-config.xml


Awaiting Reply..Thanks in Advance
Cheers
S.!.D
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would recommend you to reconsider your design. I've personally never came across a situation where I had to submit two different forms from one page. Why are you actually submitting the form to two different actions. Can you design one action that will process both the forms (or to say just one form that will contain both the warehouse and address information). That action will first persist the warehouse object, and then use its id to persist the address object...
 
Siddhesh Tawde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit, Thanks for replying,

Well thats the easy way, but thats not feasible for my project as Address table is a common table for different masters like warehouse is the one and others are users, customers, transporters, complex, consignors and so on....
and thats why I have different ActionForms and ActionClasses for all of them...

I am also using Ajax in some places, is there any way to get through this using ajax ??

Cheers
S.!.D
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The logic to insert records into the address table should be in a separate class i.e. not an action. Something like DAO should be used to do database handling. So it should not be a problem to use the DAO class in two actions. Still if you want to stick to your pattern, then the Warehouse Action can insert the warehouse row in the database and itself forward the request to the address action. So here too there will be only one form that will be submitted to the warehouse action that will contain both warehouse and address data. The warehouse action will use the warehouse data and the address action will use the address data...
 
Siddhesh Tawde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right, i have a DAO class, 1st when the address form is submitted it goes to a Action class which sends it to DAO to persist and in the same DAO it retrives the address_id which is kept in a session object to be refered by warehouse DAO while persisting warehouse data
I have one ActionClass with two different methods for the job and there are two DAOclasses, one for each
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should I consider the problem solved??
 
Siddhesh Tawde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Noo...The Problem is still there....
I just told you the structure.....
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I told you the solution. Post all the information to the address action which will insert an address record and then forward the request to warehouse action (although I personally would've not used this approach but you insisted on inserting address records in address action)...
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic