4

In a jsf application I have a table with summarized data. If I'm interested in the details I can click on a row an see the details in another page. If the managed bean of the 'master' page is ion view scope it is re-created every time I return back from the 'detail' page and I don't think it is a good idea if the user is supposed to check the details more times. I can solve putting the bean in sessions cope but this way the bean (and the data) are kept in memory also when the user is interacting with the application in a completely different section. Probably I would need a custom scope but:

  • the documentation about custom scope is poor and I'm a bit frightened about people complaining it has bugs and doesn't work well.
  • the scenario I'm dealing with seems to me quite general, so I wonder why there is no ready solution for it.

Thanks Filippo

Filippo
  • 1,123
  • 1
  • 11
  • 28

2 Answers2

2

If the detail page has to be idempotent (i.e. it's permalinkable, bookmarkable, searchbot-crawlable), just use two request or view scoped beans and use a GET link with the entity ID as request parameter to go from master page to detail page. See also Creating master-detail pages for entities, how to link them and which bean scope to choose for a concrete example.

If the detail page does not need to be idempotent, then you can always conditionally render the master and detail in the very same view or even display the detail in some modal dialog from the master page on. This way you can continue with a single view scoped bean.

In JSF side you must not be too much worried about the DB performance cost. Rather configure and finetune it in the persistence layer. In JPA for example you can setup a second level cache. If you've much more than 500~1000 items, then consider database-level pagination.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

It may be valid to reload the master page each time e.g. if the data could have changed after viewing the details page. However, if you want to keep the data available for longer than @ViewScoped your options are:

  • You should be using JEE6 of which JSF 2.0 is a part of, so look at Conversation Scope (part of CDI)
  • Some additional scopes for JEE6 CDI is available through the MyFaces CODI
  • Potentially use Session Scope and make sure you tidy up when a Request hits which is not for the Master or Details page
  • Rework your design to use Ajax, so if clicking a record on the Master page its details load in the same view. You could then use @ViewScoped

My preference would be to look at the Conversation Scope. You don't mention which JSF implementation you are running or in which environment.

planetjones
  • 12,469
  • 5
  • 50
  • 51
  • 1
    I read about Conversation Scope but it seems to me that if you have a menu from which you can go elsewhere there is no possibility to end the conversation, which has to be done explicitly calling a method of the managed bean. – Filippo Mar 01 '12 at 08:13
  • With MyFaces CODI that's an easy task. – Dar Whi Mar 07 '12 at 21:13