wood burning stoves*
The moose likes JSF and the fly likes Problem passing parameters from one page to another. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem passing parameters from one page to another." Watch "Problem passing parameters from one page to another." New topic
Author

Problem passing parameters from one page to another.

anakin volpy
Greenhorn

Joined: Jul 26, 2010
Posts: 18
Hey guys, kinda a newbie question/problem here. I'm trying to pass a parameter between two pages. Nobody answered the question in another forum so hopefully I can get some help here. Here is the code I have.



I need to retrieve the projects.piD value on the new page. The action utilize a navigation rule that goes to an update page. I am getting and setting the projects.piD value in a backing bean handler called projectHandler. I am able to get the value but once the navigation rule is executed and i'm redirected to a new page, the values are lost in the projectHandler bean.

Here is the projectHandler bean


The Faces-Config code and navigation rule.



The JSFUtils function is just a custom function that does all this jazz: (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(paramName);


Thanks for any help. If you need any more info to help me out, let me know.
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

prime time to make a helper and add it to a general jsf lib for future use.


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

JSF isn't really about "pages", it's about the backing beans. Pages are Views of the backing beans, which are the Models in the JSF MVC architecture.

You can pass information from one bean to another by injecting the second bean into the first bean, then having an action processor use invoke methods on the injected bean. If you do that, then when another View is invoked that references the second bean, it will already have the data and there's no need for elaborate or specialized "inter-page" data passing. In fact, no need for specialized JSF tags or even use of "javax.faces" classes at all. Just POJOs.


Customer surveys are for companies who didn't pay proper attention to begin with.
anakin volpy
Greenhorn

Joined: Jul 26, 2010
Posts: 18
Tim Holloway wrote:JSF isn't really about "pages", it's about the backing beans. Pages are Views of the backing beans, which are the Models in the JSF MVC architecture.

You can pass information from one bean to another by injecting the second bean into the first bean, then having an action processor use invoke methods on the injected bean. If you do that, then when another View is invoked that references the second bean, it will already have the data and there's no need for elaborate or specialized "inter-page" data passing. In fact, no need for specialized JSF tags or even use of "javax.faces" classes at all. Just POJOs.


Thanks for the reply. While I named the therad passing parameters between pages, I do understand that I'm just passing them to backing beans, so it was probably a poor choice of titles. Anyways, I probably should have named it Passing parameters between beans. The problem occurs when I do an action navigation rule. I lose all data in my projectHandler bean because the scope is request. I'm trying to pass the property as a manged property in faces-config file but the bean doesn't seem to be getting it. If you check out the code above I'm sure you'll see what I'm trying to say in words. Thanks for the response though. Any response is helpful.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

JSF isn't very kind to request-scope objects and tends to require a lot more use of session scope than most frameworks. Request scope objects are created and destroyed on EACH HTTP request. Even if the same page is displayed after the request.

JSF2 attempts to remedy this by adding a "View" scope that's sort of a temporary session scope that allows the objects with view-scope property to not be deleted between HTTP requests to the same page. However, you probably should be using Session scope for the projectHandler bean.
anakin volpy
Greenhorn

Joined: Jul 26, 2010
Posts: 18
Tim Holloway wrote:JSF isn't very kind to request-scope objects and tends to require a lot more use of session scope than most frameworks. Request scope objects are created and destroyed on EACH HTTP request. Even if the same page is displayed after the request.

JSF2 attempts to remedy this by adding a "View" scope that's sort of a temporary session scope that allows the objects with view-scope property to not be deleted between HTTP requests to the same page. However, you probably should be using Session scope for the projectHandler bean.


Thanks for the reply Tim. Switching my projectHandler scope to session kidna destroys the integrity of the application. I'll see if I can find a workaround somehow and post it back here when I figure it out.
anakin volpy
Greenhorn

Joined: Jul 26, 2010
Posts: 18
Ok guys I found the problem. I feel like an idiot. But if you notice in my faces-config file on line 28, I have <redirect/>. Well that completely ruins my <view-id>. And it stems from my laziness because with the Nav rules because I usually just copy/paste old ones, and make modifications. So removing the <redirect/> fixes it.

Thanks for the help Tim, when you mentioned the view, I started looking at my faces-config file, otherwise i'd still be lost.
 
 
subject: Problem passing parameters from one page to another.
 
Similar Threads
commandLink param problem
JSF <h:commandButton action> not working
redirect & parameter passing
Providing anchor to columns in a datatable
navigation problem from main menu