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

查看:84
本文介绍了返回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有影响。在返回 null void 时,视图范围的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.

  • Communication in JSF 2.0 - Managed bean scopes

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

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