This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Bean value not maintained in RequestScoped Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Bean value not maintained in RequestScoped" Watch "Bean value not maintained in RequestScoped" New topic
Author

Bean value not maintained in RequestScoped

maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
In my project am using @ManagedBean, @RequestScoped. I am new for JSF. Am using 4 pages in my project. My problem was bean values not maintain in the second, third and fourth pages. In First page only bean values maintained properly. Could you please advise me how to solve this issue. I have copied some sample code for reference

@ManagedBean
@RequestScoped

public class ArticlePrepToolManagedBean implements Runnable, Serializable {
@ManagedProperty (value="#{param.jidName}")
private String jidName;
@ManagedProperty (value="#{param.aidName}")
private String aidName;

private List<com.elsevier.ArticlePrepTool.db.ItemZipContains> usabilityDetailList = null;

public String getAidName() {
return aidName;
}
public void setAidName(String aidName) {
this.aidName = aidName;
}
public String getJidName() {
return jidName;
}
public void setJidName(String jidName) {
this.jidName = jidName;
}

public List<ItemZipContains> getUsabilityDetailList() {
return usabilityDetailList;
}

public void setUsabilityDetailList(List<ItemZipContains> usabilityDetailList) {
ArticlePrepToolManagedBean.usabilityDetailList = usabilityDetailList;
}

}

Thanks for looking into this.
Gabriel Vince
Greenhorn

Joined: Feb 05, 2009
Posts: 24
Hello Maria,
as the name of the 'request scope' suggests, the bean lives only during a request. Then it's forgotten. You could use a view/session scoped bean. Then you cannot use #params, but can bind the textfields into the bean attributes directly. Another approach is to resend the parameters from each page, but it may create some security / consistency issues.
Carpe diem
Gabriel
maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
Gabriel Vince wrote:Hello Maria,
as the name of the 'request scope' suggests, the bean lives only during a request. Then it's forgotten. You could use a view/session scoped bean. Then you cannot use #params, but can bind the textfields into the bean attributes directly. Another approach is to resend the parameters from each page, but it may create some security / consistency issues.
Carpe diem
Gabriel


Thanks Gabriel. My project url is (http://localhost:8080/articlepreptool/) but input of my project is jidName=AEA and aidName=10663. that input given by some other web page that is if user trigger using the following link http://localhost:8080/articlepreptool/usability.jsf?jidName=AEA&aidName=10663.

Based on that input i fetched some data in my DB (using JPA) and list out that data in the first page. But if i goes to the next page all previous data stored in that list which i got from DB was cleared that is all list values and variables which set in the bean becomes null. That problem occurred only if i used the @ManagedProperty. I used @ManagedProperty to fetch the input values comes through url, because the input values of my project comes through other web page.

Is it possible to solve this issue, if i use the view/session scoped bean? Kindly advise me.
Gabriel Vince
Greenhorn

Joined: Feb 05, 2009
Posts: 24
Hello Maria,

I'm sending you a sample. Actually - view scoped beans are alive until you stay on the same view (page), so moving between pages you rather use session beans. I've created a session scoped bean:



and then I've created a JSF page with parameter mapping:


please note the metadata tag, it can be used in the faces-config.xml as well.

where page2 is as follows:



you can use a request scoped bean, but then you will have to have your parameters in hidden form fields in each of your pages. And Voila! It works too.

as well have a look at the JSF 2.0 - Bookmarability/View Parameters , there are some hints to process requests parameters too.

Kind regards
Gabriel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean value not maintained in RequestScoped
 
Similar Threads
Problem with navigation in JSF with Filter
Injection problem - not quite sure if this is something i should be using injection for
How To initialize one bean from another bean
Acessing a managed bean from another managed bean
Annotations Not Working