为什么JSF保存组件树状态? [英] Why does JSF save component tree state?

查看:95
本文介绍了为什么JSF保存组件树状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

托管bean状态和组件树状态之间似乎有所不同.您可以使用 @RequestScoped @SessionScoped 之类的注释来控制托管bean的状态,但是似乎您无法选择是否保存组件树状态(尽管您可以选择将其保存在服务器还是客户端上.)

There appears to be a difference between managed bean state and component tree state. You can control managed bean state by using annotations like @RequestScoped and @SessionScoped, but it seems you don't have a choice in whether the component tree state is saved or not (although you can choose whether it is saved on the server or client).

似乎组件树状态仅应在单个请求期间才需要,以作为临时数据结构来帮助处理请求.对于每个请求,应从头开始对其进行重建.使用JSF 2.0,部分状态保存使情况更好,因为只保存了表单数据,但是我不明白为什么从先前的请求中获取均匀的表单数据还是有用的.

It seems like component tree state should only be needed for the duration of a single request as a temporary data structure to help process a request. It should be rebuilt from scratch for each request. With JSF 2.0 partial state saving makes the situation better because only form data is saved, but I don't understand why having even form data from the previous request is useful.

如果您的应用程序仅使用请求范围托管的Bean,则在请求之间保存组件树状态尤其没有意义.即使您的应用程序具有会话范围托管的Bean,我也会假设托管的Bean可以保持状态,并且组件树在请求之间仍不需要任何状态.

If your application uses only request scope managed beans then it especially doesn't make sense to save component tree state between requests. Even if your application has session scope managed beans I would assume that the managed beans would hold the state and the component tree still wouldn't need to have any state between requests.

推荐答案

因为可以根据初始请求以编程方式更改组件树.每当必须处理表单数据时,这不一定会在后续请求中重现.

Because the component tree can be altered programmatically depending on the initial request. This is not necessarily reproduceable on the subsequent request whenever the form data has to be processed.

此外,我给您的印象是您认为组件树也包含模型值.这不是真的.它仅保留对模型值(托管Bean属性)的引用(通过表达式语言).视图状态不会复制/复制/包含模型状态.它只是一个纯UI组件树.也许您的困惑是基于此.请注意,术语表单数据"应解释为提交的值和模型值.

Further I have the impression that you think that the component tree also holds the model values. This is not true. It only holds references (by expression language) to the model values (the managed bean properties). The view state does not copy/duplicate/contain the model state. It's just a pure UI component tree. Perhaps your confusion is based on this. Note that the term "form data" is to be interpreted as submitted values and model values.

这篇关于为什么JSF保存组件树状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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