JSF中的viewstate是什么,如何使用? [英] What is viewstate in JSF, and how is it used?

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

问题描述

在JSF中,每个页面都有一个视图状态,它与提交等来回传递.

In JSF, there is a viewstate associated with each page, which is passed back and forth with submits etc.

我知道viewstate是使用页面上各种控件的状态计算得出的,您可以将其存储在客户端或服务器端.

I know that viewstate is calculated using the states of the various controls on the page, and that you can store it either client side or server side.

问题是:如何使用此值?是否用于验证在Submit时发送的值,以确保同一请求不会发送两次?

The question is: how is this value used? Is it used to validate the values sent at submit, to ensure that the same request is not sent twice?

另外,它是如何计算的-我意识到Richfaces的计算方式可能与myfaces不同,但是一个主意会很好.

Also, how is it calculated - I realise that richfaces may be calculated differently from myfaces, but an idea would be nice.

谢谢.

推荐答案

问题是:这个值如何 用过的?它是否用于验证 在提交时发送的值,以确保 相同的请求不会发送两次?

The question is: how is this value used? Is it used to validate the values sent at submit, to ensure that the same request is not sent twice?

之所以存在viewstate的最初原因是因为HTTP是无状态的.跨请求的组件状态需要以一种或另一种方式维护.您可以将状态存储在服务器上的内存中,然后将其绑定到会话,或者每次在请求/响应中将其序列化/反序列化.

The original reason why the viewstate exists is because HTTP is stateless. The state of the components across requests need to be maintained one way or the other. Either you store the state in memory on the server and bind it to the session, or serialize/deserialize it in the request/response each time.

AFAIK,viewstate不用于检测重复提交,但是如果您附加了时间戳或类似的时间戳,则可以使用它.

AFAIK, the viewstate is not used to detect double submit, but it could if you attach a timestamp or something similar to it.

还可以对viewstate进行加密,以确保客户端不会对其进行更改.

The viewstate can also be encrypted to make sure the client doesn't alter it.

另外,它是如何计算的-我意识到 可以计算出丰富的面孔 与我的面孔不同,但有一个主意 会很好.

Also, how is it calculated - I realise that richfaces may be calculated differently from myfaces, but an idea would be nice.

每个组件都有责任通过saveStaterestoreState保持其状态(请参见教程).因此,不同的组件套件会导致不同的视图状态.同样,不同的JSF实现可能会导致不同的视图状态.

Each component is responsible to persist its state with saveState and restoreState (see this tutorial). So different component suites result in different view state. Similarly, different JSF implementations might result in different view state.

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

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