I am using SessionScoped Managed Beans in my application:
@ManagedBean
@SessionScoped
public class SampleBean{
private String value;
//getters and setters
}
I have my controller:
@ManagedBean
@SessionScoped
public class SampleController{
@ManagedProperty(value = "#{sampleBean}")
private SampleBean sampleBean;
public String showConfirm() {
return "confirm";
}
public String showComplete() {
return "complete";
}
//getters and setters
}
The logic is that, I have a startup page where I enter the values.Then it goes to the confirm page and then finally to the Complete page. I have to show the data entered in startup page in the remaining pages.
The startup page is as follows:
startup.xhtml
<h:inputText value="#{sampleBean.value}">
<h:commandLink value="Confirm" action="#{sampleController.showConfirm()}">
In the confirm page, I want to show this data.
confirm.xhtml
<h:outputFormat value="#{sampleBean.value}">
However, i don't get any value displayed here.
I tried putting these values into the sessionMap in the showConfirm()
method.
public String showConfirm() {
FacesContext context = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("sampleBean", sampleBean);
return "confirm";
}
But then also, I am not able to view these values in confirm.xhtml.
Only if I use <h:outputFormat value="#{sessionScope.sampleBean.value}">
, the values get displayed.
Also, I would like to do this using SessionScope only since all this is part of a bigger application with sessions.
Is there an alternatve to do it?