2012-08-23 97 views
1

我試圖使用ICEfaces創建一個簡單的Web應用程序並遇到問題。ViewState在每次請求後都會隨着ICEfaces增長

這裏是網頁:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core"> 

<h:head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>test</title> 
</h:head> 
<h:body> 
    <h:form> 
     <h:commandButton value="Action" action="#{test1.action}" /> 
    </h:form> 
</h:body> 
</html> 

下面是支持bean:

@ManagedBean(name = "test1") 
@SessionScoped 
public class Test1 { 
    public Test1() { 
    } 

    public void action() { 
     System.out.println("action invoked"); 
    } 
} 

這裏是web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0"> 
    <display-name>regconf</display-name> 
    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>*.xhtml</url-pattern> 
    </servlet-mapping> 

    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Production</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name> 
     <param-value>1</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
     <param-value>resources.application</param-value> 
    </context-param> 
    <context-param> 
     <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description> 
     <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
     <param-value>client</param-value> 
    </context-param> 

    <listener> 
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class> 
    </listener> 
</web-app> 

問題是ViewState的大小很大(用Firebug檢查),每次點擊「Action」按鈕時它會增大。在第一次請求之後,它是32 KB,在第二個61 KB之後,然後是94 KB,128 KB等等(在我看來,它總是保存先前請求的狀態)。

當我將javax.faces.STATE_SAVING_METHOD參數的值設置爲server時,行爲會發生變化 - 在這種情況下,所有工作都正常,每次請求後ViewState都會保持較小(使用StateManager在服務器端進行檢查)。

我使用Mojarra 2.1.12(也試過MyFaces - 相同的結果),ICEfaces 3.1.0和Tomcat 7.0.29。

在此先感謝。

回答

1

ICEfaces的需要服務器端的狀態保存,所以你應該設置如下:

<context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>server</param-value> 
</context-param> 
相關問題