Difference between returning null and “” from a JSF action

前端 未结 1 1448
谎友^
谎友^ 2020-11-27 17:43

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 ret

相关标签:
1条回答
  • 2020-11-27 18:14

    Is the above statement correct (accurate)?

    Yes. Instead of returning null you can also just return 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)?

    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.


    In what situations should one be used over the other?

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

    See also:

    • Communication in JSF 2.0 - Managed bean scopes
    0 讨论(0)
提交回复
热议问题