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
Solved

Transferring objects between JSF pages

Posted on 2009-07-14
5
572 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
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.
0
 

Author Comment

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

Expert Comment

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

Author Comment

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

Accepted Solution

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
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.

856 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