java - 从 JSF 操作返回 null 和 ""之间的区别

标签 java jsf navigation

据我了解,当 JSF 操作返回 "" (空字符串)时,用户会停留在当前页面上,但会刷新 View 。但是,当操作返回 null 时,用户仍停留在当前页面上,但旧 View 被重用。我的问题是:

  1. 上述说法是否正确(准确)?
  2. 如果是,那么这意味着什么?具体来说,使用其中一个与另一个对页面上的数据(例如 JSF UI 组件中的值,或存储在 DataTable 中的请求范围 bean 中的数据)有什么影响?
  3. 在什么情况下应该使用一种而不是另一种?

最佳答案

Is the above statement correct (accurate)?

是的。除了返回 null 你也可以只返回 void


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)?

没有请求范围的 bean。它只对 JSF2 View 范围的 bean 有影响。返回 nullvoid 时, View 范围的 bean 实例将保留在下一个请求中,否则将重新创建。


In what situations should one be used over the other?

如果您想在后续请求中保留 JSF2 View 范围的 bean。

另见:

关于java - 从 JSF 操作返回 null 和 ""之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8744162/

相关文章:

java - JTextArea 的前景色没有改变

java - HHH000431 : Unable to determine H2 database version, 某些功能可能无法工作

arrays - 如何在支持 bean JSF 2.0 中为数组赋值

java - Richfaces 仅在一页上启用

javascript - 尝试创建带有菜单下拉菜单的导航栏,但我的菜单项似乎不想显示或者它们隐藏在我的父容器中

html - 向导航栏添加多个背景图像/颜色

JavaFx 我的 css 文件无法正常工作

java - 事务方法的递归 ROWNUM 使用

javascript - 如何将当前带有 javascript 图表的 xhtml 页面转换为 pdf

安卓应用 : How to change fragments in Navigation Drawer