Transferring objects between JSF pages

Posted on 2009-07-14
Medium Priority
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
  • 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 1500 total points
ID: 24884759
Use the same bean for both the pages.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.

607 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