2013-07-20 22 views
10

我有一個page1.jsf,在這個頁面中我有一個命令按鈕,將對象放入ELFlash中,並重定向到page2.jsf。在這個頁面中,我通過ELFlash恢復對象。一切正常。不過,雖然用戶仍然page2.jsf,對於每一個Ajax請求,Tomcat的顯示此警告消息:從JSF獲取警告:當我們嘗試設置閃存的傳出cookie時,響應已經提交

20/07/2013 09:43:37 com.sun.faces.context.flash.ELFlash setCookie 
WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request. 

是什麼究竟意味着什麼?

+2

這確實意味着Flash在Mojarra仍然被破壞。你正在使用哪個Mojarra版本? – BalusC

+0

它可能與[this]相關(http://stackoverflow.com/questions/17668986/exception-about-flash-with-jsf-2-2-1)? –

+0

可能是[JSF-2896](https://java.net/jira/browse/JAVASERVERFACES-2896)。我仍然在Mojarra-2.2.5中看到這一點,在複雜頁面中使用Post-Redirect-Get和Omnifaces的addFlash()。 – mabi

回答

-1

閃光,因爲它應該建議該名稱是爲了在jsf的生命週期之間的一種臨時容器概念。重點是以下幾點:存儲在閃存中的對象將在他將遇到的下一個視圖中提示給用戶(請記住,jsf遵循mvc),因此在「使用」之後它將消失,即將被刪除。

我認爲這就是爲什麼你會得到這樣的錯誤,而這與mojarra沒有直接關係。

+0

你根本沒有回答具體的問題。理想情況下,這些警告消息不應該顯示。您的答案中沒有提供解決方案。 – BalusC

+0

關於'存儲到閃存中的任何值將在下一個請求中不可用'。 :o – LMG

+0

這只是警告信息,它只是告訴我預期的行爲,這意味着沒有理由顯示在警告中,而我的問題是,爲什麼會發生這種情況。 –

3

我認爲這個問題可能與http chunking有關。 解決方案是增加響應緩衝區大小。 之後,cookies將被正確設置並且Flash Scope也可以工作。

使用此代碼:

public class FlashScopeFixerFilter implements Filter { 
@Override 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 
    // Below line: response.getWriter() must be invoked to buffer size setting work. Just DO NOT touch this! 
    response.getWriter(); 
    HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response); 
    wrapper.setBufferSize(10000000); 
    chain.doFilter(request, wrapper); 
} 

@Override 
public void init(FilterConfig arg0) throws ServletException {} 
@Override 
public void destroy() {} 
} 

而且在web.xml:

<filter> 
    <filter-name>FlashScopeFixerFilter</filter-name> 
    <filter-class>dk.sd.medarbejderdata.common.FlashScopeFixerFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>FlashScopeFixerFilter</filter-name> 
    <url-pattern>*.xhtml</url-pattern> 
</filter-mapping> 
+0

這是目前唯一對我們有用的東西。我們的日誌在mojarra 2.2.14中仍然充滿了這個令人討厭的警告 – Steve

3

,而不是使用過濾器在@Rafalķ答覆中提到的,你也可以通過增加響應緩衝區大小設置您的上下文參數web.xml

<!-- increase buffer size to avoid JSF1095 errors --> 
<context-param> 
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name> 
    <param-value>131072</param-value> 
</context-param> 

大小以字節爲單位給出並且應該大於您的最大頁面。您可以通過點擊右鍵並選擇View Page Info輕鬆檢查Firefox中的頁面大小。

相關問題