Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

View scope vs application scope for beans

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 24894
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic