• Post Reply Bookmark Topic Watch Topic
  • New Topic

View scope vs application scope for beans

 
Jorge Martinez
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy,

Viewing this example of pagination http://www.javacodegeeks.com/2012/04/lazy-jsf-primefaces-datatable_11.html and other similar beans for pagination, why do they do these beans view scoped? These beans dont contain any properties for a form so they could be application scoped, right?

Thanks
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Application scope would be a horrible choice for this example.

Objects in application scope are shared with every user of the webapp, and they are not thread-safe. In particular, there's likely to be pagination conflicts.

This is bad code to begin with, since he's using a List directly as the UI datamodel instead of wrapping it in a JSF DataModel object. That means that he loses the DataModel functionality.

So the proper scopes for a dataTable's UI model object are Session scope and View scope only.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!