【发布时间】:2016-05-11 08:46:53
【问题描述】:
我正在尝试使用 JSF 和 Primefaces 在 View1 到 View2 之间重定向时传递一个对象。
我正在使用 JSF Flash 范围来执行此操作,该对象确实传递到第二个视图,但我仍然收到此警告:
com.sun.faces.context.flash.ELFlash setCookie
警告:JSF1095:在我们尝试为 flash 设置传出 cookie 时,响应已经提交。存储到闪存中的任何值在下一次请求时都将不可用。
即使经过多次重定向,flash cookie 也不会被删除。
View1.xhtml
<ui:composition xmlns=...... template="../../../BaseTemplate.xhtml">
<ui:define name="templateContent">
<mm:MyComponent />
</ui:define>
</ui:composition>
MyComponent.xhtml
<html xmlns= ......>
<composite:interface componentType="usersListComponent">
</composite:interface>
<composite:implementation>
<h:form>
<p:commandButton action="#{cc.passObject}" value="passMyObject" />
</h:form>
</composite:implementation>
</html>
MyComponent.java
@FacesComponent("myComponent")
public class MyComponent extends UIComponentBase {
private MyObject objectToPass;
public String passObject() {
ExternalContext externalContext= FacesContext.getCurrentInstance().getExternalContext();
externalContext.getFlash().put("objectToPass", objectToPass);
return "View2";
}
}
View2Controller.java
@ManagedBean
@ViewScoped
public class View2Controller implements Serializable {
@PostConstruct
public void init() {
MyObject ob = (MyObject) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("objectToPass");
......Do Something with MyObject
}
}
已解决!!!!!!
我不确定this 是不是最好的方法,但它对我有用..
问题在于 http 缓冲区大小和 jsf 生命周期,cookie 是在写入响应后写入的,缓冲区太小而无法容纳两者。
【问题讨论】:
-
哪个 JSF 实现/版本?
-
jsf-api:2.2.13 jsf-impl:2.2.13
标签: jsf jsf-2 primefaces flash-scope