JSF と Primefaces を使用して、View1 から View2 へのリダイレクト中にオブジェクトを渡そうとしています。
そのために JSF Flash スコープを使用しています。オブジェクトは 2 番目のビューに渡されますが、まだ次の警告が表示されます。
com.sun.faces.context.flash.ELFlash setCookie
警告: JSF1095: フラッシュの送信 Cookie を設定しようとした時点で、応答は既にコミットされていました。フラッシュに保存された値は、次のリクエストでは使用できません。
また、リダイレクトが数回行われた後でも、フラッシュ 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
}
}
解決済み!!!!!!!!
これが最善の方法かどうかはわかりませんが、私にとってはうまくいきました..
問題は http バッファ サイズと jsf ライフサイクルにあります。応答が書き込まれた後に Cookie が書き込まれ、両方を含めるにはバッファが小さすぎます。