How can I pass a request-scoped object from one request to another?

Hi& I'm currently using JSF 1.1 and all of my Googling hasn't been able to answer a question about passing bean objects from one jsp page to another.  Hopefully someone here can point me in the right direction.  This seems like something that should be a common function.

This is my situation:  

I have a managed-bean (busBean), set up with "request" scope in the faces-config.xml.  I also have two jsp pages... call them A.jsp and B.jsp, each of which has a backing bean (A.java and B.java).

In A.jsp, a list of businesses is displayed in a grid.  The user selects a row from the grid to display/edit the details of that record on B.jsp.  In the backing bean for A.jsp (A.java) the row ID that the user clicked on is retrieved from the grid and an instance of the managed-bean busBean is created and populated with the ID from the grid.  I use the following line of code to pass the newly created busBean object (containing the detailed information about the business) to B.jsp:

                FacesContext context = FacesContext.getCurrentInstance();
                Application app = context.getApplication();
                app.createValueBinding("#{busBean}").setValue(context, busBean);

The UI components on B.jsp are value bound to the properties in busBean, so the detailed information that was retrieved from the database is visible.  Example:
                <h:inputText id="txtBusinessName" value="#{busBean.busName}" />

No problem so far.  However, once the user edits the information on B.jsp, they click a "Save" button (which executes a save method in the backing bean B.java) that should update the values in the database.  This is where my problem occurs.

Because busBean is declared as a request-scoped object, the object seems to be destroyed after B.jsp has finished rendering, and so when I click "save", a new instance of busBean is created.  This creates a problem because there is information, like the Business ID (the primary key on the object), that is stored in the bean but not in controls on the web page.  So when I click save and the new copy of busBean is created, the only properties in the bean that have values are the ones that came from UI Components on the screen; the rest of the bean properties are all just default values that were created when the bean was initialized.  (For example, Business ID is now 0 instead of the ID from the database.)

I have no problems if I change the scope of busBean to session instead of request or if I attach the bean to the SessionMap instead of using the value binding code above, so I'm pretty sure I'm just not quite understanding how to do the scope properly& but really, I don't want the busBean to be a session object.  What I'd really like is for it to remain a request-scoped object, but I'd like to somehow pass the populated object on to the next request before my first request is destroyed so that I can update the database from B.jsp.

Also, because of our security recommendations, I'm not supposed to put the whole object in a hidden tag of any kind on the JSP page, so I can't pass the object that way.

Has anyone had to do this sort of thing?  Am I making this more complicated than it has to be?!  Or am I forced to make this bean a session bean?

Much thanks&
killerwhaletankAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

m00003643Commented:
From what you've described you would have to put it in the Session.  Most large scale applications solve this sort of a problem using a PageFlow scope that would be managed by some sort of an MVC (or otherwise) implementation.

It should be fairly evident that the Request object does not persist across multiple requests, and if your requirements prevent you from storing it in a hidden form, then your best remaining option would be to store it in the Session.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anjukCommented:
Hi killerwhaletank,
i saw your question and i think you can help me in my problem.

i am selecting a row and want to edit that particular row in database. my problem is after selcting(using check-box) i click on edit button, so there i am not able to see selected row value in table.

i have a showproject.jsf and editproject.jsf and my action method editProject() is in ProjectMaster.java.

on showproject.jsf i check a row then click on edit button.

can you guide me regarding this and please share your full code of edit functionality.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.