What managed bean scope should I use?

我的梦境 提交于 2019-12-25 03:52:04

问题


I have 3 different page where I use list of Users.

First page contains dataTable with users from one session scope managed bean. On that page I can change selected user details.

Second page also contains dataTable with users, but from different session scope bean. On this page I delete users from dataTable (list of users) and data base too.

I realized that this is not good idea, because if I made changes on one user, that changes will not be shown on page where I delete users.

Is application scope bean with only list of users a solution?


回答1:


Is application scope bean with only list of users a solution?

No, it won't solve the problem you're facing and you'll after all run into concurrency issues as a webapplication is usually a multi-user environment and you'd need to make everything synchronized to prevent nasty ConcurrentModificationException and like. An application scoped bean is namely shared between all users of the webapp. It makes no sense to hold request/view scoped data in an application scoped bean, even the session scope is too broad.

Your problem is thus that the session scope is too broad. You'd like to refresh the list on every fresh new GET request. Best to achieve this is to put the bean in the request or, better, view scope. The bean which edits the user detail could be another one, but this can in turn also easily be a just a property of the first bean whenever you don't want to make the edit page a bookmarkable GET request.

See also:

  • Preserving bean values between views
  • How to choose the right bean scope?


来源:https://stackoverflow.com/questions/7153909/what-managed-bean-scope-should-i-use

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!