Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSF页面中访问SessionScoped bean_Session_Jsf 2_Managed Bean_Facescontext - Fatal编程技术网

在JSF页面中访问SessionScoped bean

在JSF页面中访问SessionScoped bean,session,jsf-2,managed-bean,facescontext,Session,Jsf 2,Managed Bean,Facescontext,我正在应用程序中使用SessionScoped托管bean: @ManagedBean @SessionScoped public class SampleBean{ private String value; //getters and setters } 我有我的控制器: @ManagedBean @SessionScoped public class SampleController{ @ManagedProperty(value = "#{sampleBean}") priva

我正在应用程序中使用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()}">
但是,我也无法在confirm.xhtml中查看这些值

仅当我使用
时,才会显示值。 另外,我想使用SessionScope来实现这一点,因为所有这些都是带有会话的更大应用程序的一部分。
有替代方法吗?

您可以通过以下方法从视图通过控制器bean访问sessionScoped bean:

<h:inputText value="#{sampleController.sampleBean.value}">


通过在控制器bean中添加此托管属性的getter/setter。

您的会话范围bean应该实现可序列化接口才能正常工作。请参见

我尝试在
确认
页面中给出
,但它仍然没有显示任何值。视图中可能有什么内容未显示。。您可以发布视图的代码吗?我尝试使用
打印会话范围。我的
示例控制器在会话范围中不显示。我相信我在我的SampleController中做了一些错误的事情。它可以成为托管bean构造函数吗?我尝试了您的精确示例,它运行良好,您能将两个托管bean的全部代码+视图放在一起吗?您是否忘记使用
标记?谢谢,但我使用了
标记。我觉得我的控制器有问题。问题的所有者没有表示检测到任何异常;此外,该示例在没有任何
Serializable
实现的情况下运行良好。我尝试使用
Serializable
接口实现,但它不起作用。
public String showConfirm() {

FacesContext context = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("sampleBean", sampleBean);

return "confirm";

}
<h:inputText value="#{sampleController.sampleBean.value}">