Reputation: 315
I am new for JSF. In my project am using @ManagedBean, @RequestScoped. Am using 4 pages in my project. My problem was bean values not maintain in the second, third and fourth pages. Am using getter and setter properly. If i not use @ManagedProperty the bean value maintained properly. But i need to use the @ManagedProperty. 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;
}
}
My project url is (http://localhost:8080/articlepreptool/) but input for my project is jidName=AEA aidName=10663. that input given by some other webpage that is if user trigger using the following href "PrepTool". Depends on the input i fetched some data in my project DB (using JPA) and list out the data in the first page. But if i goes to 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. So could you please advise me how to solve this issue.That problem occured 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.
Upvotes: 0
Views: 840
Reputation: 1109182
A @ManagedProperty("#{param.foo}")
basically sets the HTTP request parameter with name "foo"
as a bean property directly after bean's construction. If you're retrieving null
values for them, then it simply means that those parameters are not present in the HTTP request.
Assuming that you're navigating by a plain link, then you need to fix your links to include the request parameters:
<h:link value="Go to page2" outcome="page2">
<f:param name="jidName" value="#{bean.jidName}" />
<f:param name="aidName" value="#{bean.aidName}" />
</h:link>
This will result in something like:
<a href="page2.xhtml?jidName=foo&aidname=bar">
This way those parameters can be set as bean properties.
Alternatively, instead of @ManagedProperty
you could also use <f:viewParam>
on all pages and add includeViewParams=true
to the outcome. See also ViewParam vs @ManagedProperty(value = "#{param.id}")
If you're navigating by a form submit, then there's really no reason to use them. Or you must be abusing forms instead of links for plain vanilla page-to-page navigation.
Upvotes: 1