• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multi page form - MDB or SFSB ?  RSS feed

 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My question may look long, but I believe it is a simple and common problem. I just want to be very clear.

I have a process which involves 3 forms � form 1 to form 3.

I am using Struts, and I have 1 form for all the fields found in the 3 forms. I also have 1 Action class to manage the submission requests for the 3 forms.

What I want to achieve is, I want to :
1)ensure that I get back to the user as fast as I can after submission of form 1 and 2.
2)Minimise the risk of hitting error/exception after submission of form 1 and 2.
3)Want to persist (into DB) info from form 1 (and 2) if only form 1 (and 2) are completed.

In short, I want the user to be able to go through form 1-3 without problems.

As such, I hope not to go deep into the business and integration layers during submission of form 1 and 2. Although I wish to save the info from form 1 and 2 into the DB, they can be delayed till later (after form 3)� this delay is the trade off which I am willing to give in for a problem-free user experience for the 3 forms.

I do not want the user to wait a longer time for the system to save form 1 and 2 info into the DB. Besides, the risk of hitting error is higher when we go right back to the system, which is the DB.

I have 2 solutions in mind :
1)Use Message Driven Bean to save the info into DB after form 1 and form 2. Since the action class only dumps the msg into a Queue (async call), it can get back to the user very quickly.
2)Use Stateful Session Bean to safe form field values of form 1 and 2 into the SFSB�s client state� and return the sync call to the action class quickly. We can then ask the SFSB to save all the info (which it has collected) into the DB after form 3 has been submitted.

Question:
1)Which 2 solutions above is better ? And why ?
2)Solution 2 : Since the Struts Action class is a non-thread-safe class, which, a single instance could be used by many users at any one time, will my Struts Action class call the correct SFSB instance when a user submit say�form 2 (or 3) ?



Thanks in advance.
[ November 27, 2005: Message edited by: gundum hoi ]
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use Session for managing such scenario. by session i mean http session if your application is not distributed over more than one application server.
using a SB ,if your overall solution is not based on EJB, is not appropriated.
using an MDB bring more complexity and load to your system while it not recommanded to use MDB for such condition.

About your multi user environment question :
Yes Struts manage things and you do not need to worry about it.


HTH
 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

You suggested saving in the HTTP session. OK, actually the information is already in the HTTP session because I can configure Struts to save its Struts form bean in the HTTP session.

With this solution, my save-in-DB logic/code will only be after page 3 submission. I can get back to user very quickly after submission of page 1 and 2 because I practically do nothing in the Action class...since the Struts framework auto-saves form field values into the form bean.

But if my user did not complete the form...say, left the PC after form 1 or 2, I do want to save the partial form info into the DB. What is the recommended way to do this ? Will the servlet/jsp container alert me...or give me some kind of callback when a user's http session expires (and along with it, I'll lose the partially filled form bean) ?

How do I make sure I do not lose any form bean information, although partially filled, when the http session times out ?

Thanks again.
[ November 28, 2005: Message edited by: gundum hoi ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the HttpSessionBindingListener interface. Place the code which calls the EJB to save the data to the DB in your implemented valueUnbound() method, which the servlet container will call as soon as the session is invalidated.
 
Pranav Shukla
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are just looking for a callback from container, you could use HttpSessionListener and update the DB from session scoped form bean before letting the session expire.
 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK...since my Struts form bean is the object that is stored in the http session, and if my struts form bean implement one of those interfaces, the form bean gets notified when session is about to expire...so that there is a chance for me to persist the information into the DB.

But good design dictates that I should not have any logic in the form bean. It should only have setters/getters, validate and maybe a reset method in it (form related operations). I think even calling a SB to persist its info is a no-no...as, as far as I know, form beans should not call SB or any other objects.

Any good advice on the proper way to code ?

Thanks again.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am no Struts expert, but surely you would invoke the EJB's method from the Action class?
 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Session Bean calling should be done from the Action class...but the problem is, my Form Bean is the one being notified (callback) by the container ...and not the Action class.

Many thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!