简体   繁体   English

如何在JSF中减少javax.faces.ViewState

[英]How to reduce javax.faces.ViewState in JSF

What is the best way to reduce the size of the viewstate hidden field in JSF? 减少JSF中viewstate隐藏字段大小的最佳方法是什么? 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. 我注意到我的视图状态大约是40k,这会下降到客户端并在每次请求时返回到服务器,并且响应通常会发送到服务器,这对用户来说是一个显着的减速。

My Environment JSF 1.2, MyFaces, Tomcat, Tomahawk, RichFaces 我的环境JSF 1.2,MyFaces,Tomcat,Tomahawk,RichFaces

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. 这应该只向客户端发送一个id,并保持服务器上的完整状态。 Simply add the following to the file web.xml : 只需将以下内容添加到web.xml文件中:

 <context-param>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>server</param-value>
 </context-param>

If you are using MyFaces you can try this setting to compress the viewstate before sending to the client. 如果您使用的是MyFaces,则可以尝试此设置以在发送到客户端之前压缩视图状态。

<context-param>
    <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
    <param-value>true</param-value>
</context-param> `

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. 您可能希望根据您的要求尝试使用不同的压缩算法/实用程序,但由于浏览器默认情况下已经使用了GZip,因此我不确定您可以获得多少。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 p:commandButton操作丢失javax.faces.ViewState - javax.faces.ViewState lost on p:commandButton action 如何在jsf 2中使用参数“javax.faces.FACELETS_SUFFIX” - How to use parameter “javax.faces.FACELETS_SUFFIX” in jsf 2 什么是JSF中的viewstate,它是如何使用的? - What is viewstate in JSF, and how is it used? JSF:我的应用程序中未引用 javax.faces.resources - JSF: javax.faces.resources is not referenced in my application JSF所需的库是什么/在哪里(特别是javax.faces的东西) - What / where are the required libraries for JSF (specifically javax.faces stuff) JSF应用程序中带有JMeter的javax.faces.application.ViewExpiredException - javax.faces.application.ViewExpiredException with JMeter in JSF Application 如何在jsf selectOneMenu中访问选定的标签和选定的描述,其中selectOneMenu与javax.faces.model.SelectItem对象绑定? - How to access the selected label and selected description in jsf selectOneMenu where selectOneMenu is bound with javax.faces.model.SelectItem objects? JSF 2.3 - 无法调用“javax.faces.context.FacesContext.getAttributes()”,因为“this.context”是 null - JSF 2.3 - Cannot invoke "javax.faces.context.FacesContext.getAttributes()" because "this.context" is null JSF部署错误“在javax.faces.context.FacesContext.isProcessingEvents(FacesContext.java:300)” - JSF Deploy Error “at javax.faces.context.FacesContext.isProcessingEvents(FacesContext.java:300)” javax.faces.webapp.FacesServlet如何通过HTTP工作? - How javax.faces.webapp.FacesServlet works over HTTP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM