How to reduce javax.faces.ViewState in JSF

2019-03-09 03:23发布

What is the best way to reduce the size of the viewstate hidden field in JSF? I have noticed that my view state is approximately 40k this goes down to the client and back to the server on every request and response espically coming to the server this is a significant slowdown for the user.

My Environment JSF 1.2, MyFaces, Tomcat, Tomahawk, RichFaces

3条回答
贼婆χ
2楼-- · 2019-03-09 03:38

One option is to completely save the view state on client side but you may face some problem such as not being able to Serialize the object. You may want to try using different compression algorithm/utility based on your requirement but since the browser will already use the GZip by default I am not sure how much you can gain.

查看更多
家丑人穷心不美
3楼-- · 2019-03-09 03:46

Have you tried setting the state saving to server? This should only send an id to the client, and keep the full state on the server. Simply add the following to the file web.xml :

 <context-param>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>server</param-value>
 </context-param>
查看更多
手持菜刀,她持情操
4楼-- · 2019-03-09 03:48

If you are using MyFaces you can try this setting to compress the viewstate before sending to the client.

<context-param>
    <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
    <param-value>true</param-value>
</context-param> `
查看更多
登录 后发表回答