Transferring objects between JSF pages

Posted on 2009-07-14
Last Modified: 2013-11-24
I have a JSF page that lists all active users on the system .Next to each user I have an Edit button. The page has a backing bean so in the page  use the following code to transfer the selected user to the backing bean:

<a4j:commandButton value="#{msgs.editBtn}" type="submit" reRender="dtable,table"
      alt="Click to Edit" action="#{UserListBean.edit}" id="editbtn" onclick="this.disabled=true" oncomplete="this.disabled=false">
<a4j:actionparam name="selectedItem" value="#{user.uniqueid}" assignTo="#{UserListBean.selecteditem}"/>

This successfully sets the selected user key to the backing bean.  Next the page will return result that causes the system to follow the page flow to a new page where you wold edit the selected user.

The problem is that once on the new edit page, I can't transfer the selected user from the user list backing bean to the user edit backing bean.

My thinking was that in the setSelectedUser method of the user list backing bean I will just set a session attribute holding the selected user object, then in the new user edit page I can just read that attribute back from the session and off I go.

Strangely  in the new page I cannot retrieve the session attribute even though my JSP tag is validating correctly. However if I create a method in my taglib and use that tag in the page the user object is successfully retrieved.

I'm thinking that my logic must be wrong, how is this usually done?
Question by:ChrisOz2008
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 20

Expert Comment

ID: 24847777
I would suggest that you retrieve the user details again from the db instead of transferring the user. In the scenario that someone else modifies the user data in the background you might be stuck with a stale object, so what you can do is to select the user, get the id and then do a fetch, set the data object that you want to work on in in the edit page.

Author Comment

ID: 24847897
I considered doing that however I still need to transfer the ID of the user to the new page and once I have done that I am not sure how I ca cause the fetch to occur when the new page loads.
LVL 20

Expert Comment

ID: 24847951
If you call a backing bean method to be called which loads the user when you pass the data id, that should so the trick. Precondition is to make sure you can pass the userid.

Author Comment

ID: 24848009
The problem is that if I have my backing bean on the list page instantiate backing bean for the next page that does as you say , then when the page is displayed then the that page wold have a different instance of the user edit page backing bean.

Or are you saying to use the same bean on both pages?
LVL 20

Accepted Solution

a_b earned 500 total points
ID: 24884759
Use the same bean for both the pages.

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception after setting jdbc session management 2 84
servlet doXXX methods 3 84
session migration servlets 2 51
Glassfish admin console not working 1 61
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question