返回 null 和“"之间的区别来自 JSF 动作 [英] Difference between returning null and "" from a JSF action

查看:33
本文介绍了返回 null 和“"之间的区别来自 JSF 动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,当 JSF 操作返回 ""(空字符串)时,用户会停留在当前页面,但会刷新视图.但是,当操作返回 null 时,用户仍然停留在当前页面,但旧视图被重用.我的问题是:

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:

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

推荐答案

以上说法是否正确(准确)?

是的.除了返回 null,您还可以只返回 void.

Yes. Instead of returning null you can also just return void.

如果是,那么这意味着什么?具体来说,使用一种与另一种对页面上的数据(例如 JSF UI 组件中的值,或存储在 DataTable 中请求范围 bean 中的数据)有什么影响?

没有任何请求范围的 bean.它只对 JSF2 视图范围的 bean 有影响.在返回 nullvoid 时,视图范围的 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.

If you want to retain the JSF2 view scoped bean in the subsequent request.

这篇关于返回 null 和“"之间的区别来自 JSF 动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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