This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Refreshing Page Before Loading Next Page  RSS feed

 
Martin Dubuc
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a data table in one of my page. Retrieving data for this table is an expensive operation. In this data table, there are links to navigate to other pages. What I have noticed is that when the user clicks on these links, although the application does what it has to do, which is to navigate to the appropriate page, before loading the next page, the application loads the data table for the current page once again. I do not understand why this is happening. I would like to avoid loading the data table when the application is moving on to another page.

Martin
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why that is firing, but in general, you can always have a backing bean hold onto data if you don't want to recalculate it:

Then make sure this bean has session scope.
 
Martin Dubuc
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wouldn't work in my case because the data in the table is dynamic and it must be recalculated every time the user displays the page. I just want to avoid the need to recalulate the table on page exit.

Martin
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you want to use the immediate tag

Something like this

<h:commandLink action="#{myaction.action}" immediate="true"></h:commandLink>

This skips the data update and validation sequence and displays(redirects)

Hope that helps
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thought: it could be your code's fault. Output the stack trace in the getter method in question. Perhaps it is being called directly or indirectly by your own code, in some way that you're not expecting, in this context.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Placement of a breakpoint in the getter methods and action method will show that the getters get called once or twice prior to the action method being called. I'm not sure right now why it is, but it is related to the validation phases in JSF.
 
Martin Dubuc
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting closer! Thanks for the pointers! I have added a printStackTrace statement and what I am seeing is that the com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute method is invoked. This is what causes the data table to be refreshed. I do not understand why ApplyRequestValuesPhase.execute gets called because I have set the immediate property to true on the command link. I thought at some point, maybe it was calling ApplyRequestValuesPhase.execute because there are other components that do not have the immediate property set to true... But I think I have turned all of them to false.

Martin
 
Martin Dubuc
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still haven't found a solution. I have found some mechanisms to bypass validation in case of value change event (valueChangeListener), but not for action listener or action handler.

Sounds simple, but can't find a way around it.

Martin
 
Saskia de Jong
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If its really urgent you may want to try the following hack. It's mean and ugly and won't work on any other JSF implementation that you test it on. Anyway, just before your DB operaton get a hold of the current stack trace (use the std java API for that). Find out who's calling your function, and skip or peform the DB operation depending on the outcome.

Of course, this is not the real solution to this problem.

Maybe it would also be possible to query the facescontext about the current fase? That would be a little less hacky. You could perform the DB operation then only in a specific fase.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!