From what I understand, when a JSF action returns ""
(empty String) the user stays on the current page but the view is refreshed. However, when the action returns null
the user still stays on the current page but the old view is reused. My question is:
根据我的理解,当JSF操作返回“”(空字符串)时,用户将保留在当前页面上,但视图会刷新。但是,当操作返回null时,用户仍然保留在当前页面上,但重用旧视图。我的问题是:
- Is the above statement correct (accurate)?
- If yes, then what are the implications of this? Specifically, what effect does using one versus the other have on data on the page (values in JSF UI components, or data stored in a request-scope bean in a DataTable, for example)?
- In what situations should one be used over the other?
以上陈述是否正确(准确)?
如果是,那么这有什么意义呢?具体来说,使用一个对另一个对页面上的数据有什么影响(例如,JSF UI组件中的值,或者存储在DataTable中的请求范围bean中的数据)?
在什么情况下应该使用另一个?
1 个解决方案
#1
30
Is the above statement correct (accurate)?
以上陈述是否正确(准确)?
Yes. Instead of returning null
you can also just return void
.
是。您也可以返回void,而不是返回null。
If yes, then what are the implications of this? Specifically, what effect does using one versus the other have on data on the page (values in JSF UI components, or data stored in a request-scope bean in a DataTable, for example)?
如果是,那么这有什么意义呢?具体来说,使用一个对另一个对页面上的数据有什么影响(例如,JSF UI组件中的值,或者存储在DataTable中的请求范围bean中的数据)?
Nothing on request scoped beans. It has only effect on JSF2 view scoped beans. On returning null
or void
, the view scoped bean instance will be retained in the next request, else it will be recreated.
什么都没有请求范围豆。它只对JSF2视图范围的bean有影响。返回null或void时,视图范围的bean实例将保留在下一个请求中,否则将重新创建。
In what situations should one be used over the other?
在什么情况下应该使用另一个?
If you want to retain the JSF2 view scoped bean in the subsequent request.
如果要在后续请求中保留JSF2视图作用域bean。
See also:
- Communication in JSF 2.0 - Managed bean scopes
JSF 2.0中的通信 - 托管bean范围
#1
30
Is the above statement correct (accurate)?
以上陈述是否正确(准确)?
Yes. Instead of returning null
you can also just return void
.
是。您也可以返回void,而不是返回null。
If yes, then what are the implications of this? Specifically, what effect does using one versus the other have on data on the page (values in JSF UI components, or data stored in a request-scope bean in a DataTable, for example)?
如果是,那么这有什么意义呢?具体来说,使用一个对另一个对页面上的数据有什么影响(例如,JSF UI组件中的值,或者存储在DataTable中的请求范围bean中的数据)?
Nothing on request scoped beans. It has only effect on JSF2 view scoped beans. On returning null
or void
, the view scoped bean instance will be retained in the next request, else it will be recreated.
什么都没有请求范围豆。它只对JSF2视图范围的bean有影响。返回null或void时,视图范围的bean实例将保留在下一个请求中,否则将重新创建。
In what situations should one be used over the other?
在什么情况下应该使用另一个?
If you want to retain the JSF2 view scoped bean in the subsequent request.
如果要在后续请求中保留JSF2视图作用域bean。
See also:
- Communication in JSF 2.0 - Managed bean scopes
JSF 2.0中的通信 - 托管bean范围