Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem passing parameters from one page to another.

 
anakin volpy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prime time to make a helper and add it to a general jsf lib for future use.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18169
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
anakin volpy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18169
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic