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

查看:21
本文介绍了为什么 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天全站免登陆