In JavaServer Faces (JSF) : What is the best place for controller data computation / queries" ?
-
Let's put it this way : I have a view that displays data from DB, this view uses a @RequestScoped bean to access data. A basic approach was to compute the data to view in @PostConstruct listener. But this is not Ok when actions update data as @PostConstruct is called before ... We could use a SystemEventListener for PreRenderViewEvent but this is too complex for such a simple common need. May be should we always do a POST Redirect GET ? What do you advise ?
-
Answer:
I use preRenderView events all the time for this sort of thing. Just be sure to check the value of FacesContext.getCurrentInstance().isPostback() and only do the computation if that is false. Just be aware that there's a Mojarra bug that will cause preRenderView to be executed multiple times if your page doesn't have any view params. You can work around this with a dummy view param which doesn't need the value attribute. You can also just use a phase listener which you can define for a single page. Alternatively (and probably the simpler option), in the getter for that data which you have computed, just check if the instance variable that refers to the data is null. If it is not null, just return it as is. Otherwise, compute the data and set the instance variable to it.
Steve Taylor at Quora Visit the source
Related Q & A:
- What is the best place to travel to in August (outside of the US?Best solution by Yahoo! Answers
- What is the best place to study in Europe or the UK?Best solution by Yahoo! Answers
- What's the best place to buy Japanese tissue paper?Best solution by lcipaper.com
- What's the best place to work for Nurses?Best solution by Yahoo! Answers
- What is the best PC game controller out there?Best solution by pcgamer.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.