如何禁用ViewState? [英] How to disable ViewState?

查看:198
本文介绍了如何禁用ViewState?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正从MS和ASP.NET进入Java世界,并在Java中寻找类似于基于ASP.NET组件的HTML框架.在检查了Internet上的大量链接之后,看起来JSF2(带有facelets)是最匹配的(顺便说一句,这是真的吗?还是还有其他更好的选择?).

I'm coming into Java world from MS and ASP.NET and looking for the similar to ASP.NET component-based HTML framework in Java. After reviewing tons of links in internet it looks like JSF2 (with facelets) is best match (is this true by the way? or there are other better choices?).

我现在在评估过程中遇到的问题是正确使用JSF的视图状态.我的最终使用方案将是群集的WEB服务器,并且我将不会有任何会话/服务器存储的对象,并且我不会将网络带宽用于虚拟视图状态(请参见此处其他人的一些相关问题 JSF调整).

The problem I'm encountering during evaluation right now is correct usage of JSF's view state. My final usage scenario would be a clustered WEB server and i'm NOT going to have any session/server-stored objects and i'm NOT going to use network bandwidth for dummy view state (see another guy's somewhat related problem here JSF Tuning).

我参加了一些JSF2教程,并设置了javax.faces.STATE_SAVING_METHOD =客户端将ViewState生成为440个字符的HTML(omygod,页面仅包含1个虚拟文本输入和1个提交按钮).在提交后发布"中,我只需要来自文本输入的文本(10个字符),而不需要该虚拟视图状态(440个字符).

I took some JSF2 tutorial and after setting javax.faces.STATE_SAVING_METHOD = client got ViewState generated into HTML of 440 chars (omygod, page contains just 1 dummy text input and 1 submit button). In "POST on submit" I do need only text from text input (10 chars) and not that dummy view state (440 chars).

问题是-是否可以在JSF2中禁用视图状态?

相关链接:

  • Use-case in ASP.NET - "Disable View State for a Page":
    http://www.ironspeed.com/articles/Disable%20View%20State%20for%20a%20Page/Article.aspx

关于stackoverflow的无用答案:
如何在JSF中减少javax.faces.ViewState

Not helpful answer on stackoverflow:
How to reduce javax.faces.ViewState in JSF

更新:相关链接(来自下面的评论):

无状态JSF": http://industrieit.com/blog/2011/11/stateless-jsf-high-performance-zero-per-re-request-memory-overhead

推荐答案

JSF是一个基于组件的框架,该框架具有很大的状态-因此,您需要将状态保存在某个地方,该状态可以通过网络发送给客户端,然后重新发布,或者在网络上发布.服务器端.因此,AFAIK的答案是否",您不能禁用视图"状态.但是您可以将其最小化-但是某些状态将始终需要存储.此链接是相关的.

JSF is a component based framework which is heavily stateful - so you need the state somewhere, either sent to the client over the wire and posted in again, or on the server side. So AFAIK the answer is No, you cannot disable the View state. But you can minimize it - however some state will always need storing. This link is relevant.

如果您正在寻找一个状态不是那么好的Java Web框架-那么也许看一下一些基于Action的框架,例如Struts或Stripes,这样您就可以在Request范围内工作,而无需存在(或重建)组件树回发. Play框架受到了广泛的关注-专为RESTful架构而设计.我自己对此没有经验,但是您可能需要调查.取自Play网站:

If you're looking for a Java web framework which is not so stateful - then maybe look at some Action based framework like Struts or Stripes, so you can work in Request scope and not need a component tree present (or rebuilt) on a postback. The Play framework has been gaining good press - which is specifically designed to target RESTful architectures. I do not have experience of this myself, but you may want to investigate it. Taken from the Play website:

简单的无状态MVC架构

Simple stateless MVC architecture

您的一侧是数据库,而另一侧是网络浏览器.为什么 你应该在两者之间有状态吗?

You’ve got a database on one side and a web browser on the other. Why should you have a state in between?

基于状态和基于组件的Java Web框架使易于实现 自动保存页面状态,但这带来了很多其他 问题:如果用户打开第二个窗口会发生什么?如果 用户点击浏览器的后退按钮?

Stateful and component based Java Web frameworks make it easy to automatically save page state, but that brings a lot of other problems: what happens if the user opens a second window? What if the user hits the browser back button?

这篇关于如何禁用ViewState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆