Solved

Transferring objects between JSF pages

Posted on 2009-07-14
5
565 Views
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}"/>
</a4j:commandButton>

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?
0
Comment
Question by:ChrisOz2008
  • 3
  • 2
5 Comments
 
LVL 20

Expert Comment

by:a_b
Comment Utility
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.
0
 

Author Comment

by:ChrisOz2008
Comment Utility
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.
0
 
LVL 20

Expert Comment

by:a_b
Comment Utility
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.
0
 

Author Comment

by:ChrisOz2008
Comment Utility
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?
0
 
LVL 20

Accepted Solution

by:
a_b earned 500 total points
Comment Utility
Use the same bean for both the pages.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now