Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Prerender" functionality in UI:Composition

 
vamsi kantamneni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have an application where i need to load the UI:Composition when clicked.

i have a requiremnt that i need to load the data from the database everytime i render the UI:Composition
I have tried doing
<f:event type="preRenderView" listener="#{list.loadListDetails}"/>
but it doesnt work in the UI:Composition

please help me find a way to

Call a Backing Bean Method when UI:Composition is loaded

thanks in advance
 
Tim Holloway
Saloon Keeper
Posts: 18365
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may not be able to explain this well, but "you" do not render. Rendering is done as the last stage (render response) of the JSF lifecycle and control of the rendering process is done primarily by the JSF Controller (FacesServlet) which takes the compiled View templates and produces the response data stream by merging the View with the Models (backing beans).

So you should be able to load the database data into a Model using the action method that resulted in the production of the View. The normal processes of the JSF lifecycle will take care of the rest.

In the case where no action was fired (a URL was submitted for initial page display), you need to find an alternative way to populate the Model.

As it happens, there's a single solution for both scenarios. What I do is null out my sub-model object (which is typically a DataModel wrapping the actual database data). Then, when JSF does its initial "get" on the submodel property, I do the fetch, construct the sub-model property and cache it. This is important, because otherwise the data might get loaded 5-6 times in a single page request and response time would be atrocious.

Thus, at any time, for any reason, I can refresh the data view by simply nulling out the sub-model again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic