Question

I have a search result page with a "Show more results" button. The backing bean is session-scoped and we use a preRenderView to execute the search method in the backing bean:

<f:event type="preRenderView" listener="#{SearchBean.searchSolutions}" />

The "Show more results" button is defined like this:

<h:commandButton action="#{SearchBean.onClickShowMoreResults()}">
    <f:ajax disabled="false" render=":searchResultsForm"/>
</h:commandButton>

Here is the problem I have and the steps to reproduce :

  1. Execute a search.
  2. Click on a search result that leads to a result page.
  3. Use the browser back button.
  4. Click on the "Show more results" button.
  5. Problem --> the onClickShowMoreResults() function is not called and the searchSolutions() listener method is called instead (this happens intermittently, most of the time the function is called correctly and everything is alright altought once I get the problem I can reproduce it every time with steps 2 to 4 without starting a new search).

I tried skipping the ajax requests in the listener method (as explained here) and it solves the problem, but this is not possible for me because there are ajax requests that need to execute the listener method (changing search criteras).

Is there something I don't understand about the preRenderView or is there another way to achieve what I am trying to do ?

Thanks for the help!

Était-ce utile?

La solution

Since I got no answer, I found a workaround this problem.

I made sure to have no ajax calls to the listener method (doing some sacrifices) and used BalusC's answer in this thread.

Using :

if (FacesContext.getCurrentInstance().getPartialViewContext().isAjaxRequest()) { 
       return; // Skip ajax requests.
}

in the listener method solves this problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top