File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Two jsps having same form beans  are similar or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Two jsps having same form beans  are similar or not" Watch "Two jsps having same form beans  are similar or not" New topic

Two jsps having same form beans are similar or not

ajay bora

Joined: Mar 31, 2006
Posts: 3
I am facing a big problem with two jsps which are having the same form bean. I am linking up three jsps which are having the same form beans as a series of steps. So the user can traverse these steps until completion . There is a sequence of back and forward buttons for each jsp. So they can navigate front and back. The problem i have is that once a user finishes step1 and goes to step2 and then if he clicks previous button to go to step1 the values he submitted are gone . In order to solve this problem i had to use sessions in action class and pain stakingly i stored all the beans in sessions and retrieved values from them and set up in the forms for navigation . I am wondering whether i am thinking in the right direction or i am wrong some where . Please help me . Are the beans supposed to be the same even if multiple jsps have the same name or each one is different.

JKPS Layout

Step1 --> 1.jsp Step 2 --> 2.jsp Step 3 --> 3.jsp

baseform is the form common for all jsp's

baseform has 3 VO's for storing values in forms
like one ,two ,three

so baseform is in this form

public class baseform extends ActionForm{

OneForm one;
TwoForm two;
ThreeForm three;


OneForm VO is used for assiging the values in 1.jsp
like <html:text name="username" property="">
1.jsp has elements like
<html:text name="username" property="baseform.two"> and so on
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Specifying scope="session" for each of the action mappings that use this form is a good way to go. If you want to navigate between these pages and have them retain previously entered values without writing to a database, using the session is your best option.

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
It seems like you have three basic options.

1) Configure your action to use request scope and store every submitted value as hidden fields on each of your three jsp pages. This solution can get ugly and you might end up passing a lot of data back and forth with each submission.

2) Configure your action to use session scope per Merrill's recommendation. This is probably the easiest way to implement wizard-like functionality.

3) Write your own code to store data in session. With this approach you have to update the session data with each page submission. This can be a hassle if your page has a lot of fields, but easy if your page just has a few selections. This is the approach that I have taken.

- Brent
I agree. Here's the link:
subject: Two jsps having same form beans are similar or not
jQuery in Action, 3rd edition