Jsf: what is the bean area for a two page page?

In a jsf application, I have a table with generalized data. If I'm interested in the details, I can click on the line and see the details on another page. If the bean-driven "master" page is the ion's viewing area, it is recreated every time I return from the "detail" page, and I don't think it is a good idea if the user needs to check the details more than once. I can decide how to put the bean in the sessions, but this way the bean (and data) is stored in memory as well when the user interacts with the application in a completely different section. I might need a custom scope, but:

  • the user area documentation is small, and I'm a little scared that people complain that it has errors and does not work.
  • The scenario I'm dealing with seems pretty general to me, so I wonder why there is no ready-made solution for it.

Thanks Filippo

+4
source share
2 answers

If the details page should be idempotent (i.e. it is permalinkable, bookmarkable, searchbot-crawlable), simply use two queries or browse the beans area and use the GET link with the object identifier as the request parameter to go from the main page to the details page . See Also Creating homepage pages for objects, how to link them, and in which bean area to select for a specific example.

If the details page does not need to be idempotent, you can always conditionally display the master and details in the same view or even display the details in some kind of modal dialog box from the main page. Thus, you can continue to use a single bean.

As a JSF, you should not worry too much about the cost of executing the database. Rather, configure and configure it in the save level. For example, in JPA you can configure the second level cache. If you have many more than 500 ~ 1000 items, then consider database pagination.

+2
source

You can reload the main page every time, for example. if the data may have changed after viewing the details page. However, if you want the data to be available longer than @ViewScoped, your options are:

  • You must use JEE6, of which JSF 2.0 is part, so look at the talk area (part of the CDI)
  • Some additional areas for JEE6 CDI are available through MyDaces CODI
  • Itโ€™s potential to use Session Scope and make sure that you clean when a request arrives that is not for the Master or Details page
  • Correct your project to use Ajax, so if you click on the entry on the main page, its data will load in the same view. Then you can use @ViewScoped

My preference would be to look at the area of โ€‹โ€‹conversation. You do not specify which JSF implementation you are using or in which environment.

+1
source

Source: https://habr.com/ru/post/1398968/


All Articles