【发布时间】:2013-09-25 21:36:19
【问题描述】:
我在我的应用程序中使用 SessionScoped 托管 Bean:
@ManagedBean
@SessionScoped
public class SampleBean{
private String value;
//getters and setters
}
我有我的控制器:
@ManagedBean
@SessionScoped
public class SampleController{
@ManagedProperty(value = "#{sampleBean}")
private SampleBean sampleBean;
public String showConfirm() {
return "confirm";
}
public String showComplete() {
return "complete";
}
//getters and setters
}
逻辑是,我有一个启动页面,我在其中输入值。然后进入确认页面,最后进入完成页面。我必须在其余页面中显示在启动页面中输入的数据。
启动页面如下:
startup.xhtml
<h:inputText value="#{sampleBean.value}">
<h:commandLink value="Confirm" action="#{sampleController.showConfirm()}">
在确认页面,我想显示这个数据。
确认.xhtml
<h:outputFormat value="#{sampleBean.value}">
但是,我没有在这里显示任何值。
我尝试将这些值放入 showConfirm() 方法中的 sessionMap 中。
public String showConfirm() {
FacesContext context = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("sampleBean", sampleBean);
return "confirm";
}
但是,我也无法在 confirm.xhtml 中查看这些值。
仅当我使用 <h:outputFormat value="#{sessionScope.sampleBean.value}"> 时,才会显示这些值。
此外,我只想使用 SessionScope 来执行此操作,因为所有这些都是带有会话的更大应用程序的一部分。
有没有替代方法?
【问题讨论】:
-
您忘记使用
<h:form>标签了吗? -
谢谢,但我使用了
<h:form>标签。我相信我在控制器中做错了什么。
标签: session jsf-2 managed-bean facescontext