18

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

David Waters
  • 11,979
  • 7
  • 41
  • 76

3 Answers3

16

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>
Thiago Chaves
  • 9,218
  • 5
  • 28
  • 25
Cristian Vat
  • 1,602
  • 17
  • 18
  • 7
    Please be aware that using server state saving increases the server memory consumption _a lot_! If you have many users (thousands) this can be a bottleneck very fast. – Marcel Sep 12 '09 at 11:21
  • 1
    I have specified both:` javax.faces.STATE_SAVING_METHOD server com.sun.faces.enableViewStateIdRenderingD FALSE ` Still not helping. I'm using Primefaces. – Damian Nov 09 '11 at 19:29
15

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> `
David Waters
  • 11,979
  • 7
  • 41
  • 76
0

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.

royalghost
  • 2,773
  • 5
  • 23
  • 29
  • My biggest concern is the size of the post from the client to the server as many users have much less upstream then downstream. No compression takes place when the client sends a request – David Waters Sep 24 '08 at 09:41