how to pass data from table view to second view controller?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.