4

I was wondering which scope to use for a CRUD Application. Using @ReqeustScoped causes an access to the database for every request. With @SessionScoped, data can be cached in the managed bean, but can cause the so called session-bloat. Moreover, it is more difficult to keep the data up to date. What would you recommend? Is there a best-practice solution. Thanks, Theo

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Theo
  • 43
  • 1
  • 3
  • 1
    I built a basic architecture for CRUD components only with @RequestScoped, and caching data. http://bluefoot.info/?p=408 – bluefoot Oct 18 '11 at 15:14

1 Answers1

2

Right, you want the scope there in between: @ViewScoped. This scope lives as long as you're submitting and navigating to the same view.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I believe this answer is tightly coupled to a specific solution which is making all the operations inside a single view/xhtml file. If one were to have three views: 1 for the record list, 1 for the detail view and 1 for the form (create and update) the answer would be either one SessionScoped bean (solution in most tutorials and code generators like NetBeans and MyEclipse) or "it depends", maybe 1 RequestScoped bean for the list and view and 1 ViewScoped bean for the form (considering AJAX components) and using input hidden to preserve the id. – Cenobyte321 Sep 15 '14 at 04:12