0

I'm using a selectonemenu combined with ajax to navigate.

JSF code

<p:selectOneMenu value="#{navigator.outcome}">                      
    <f:selectItem itemLabel="Select page..." />
    <f:selectItem itemValue="page1" itemLabel="Page 1" />
    <f:selectItem itemValue="page2" itemLabel="Page 2" />
    <f:selectItem itemValue="page3" itemLabel="Page 3" />
    <p:ajax event="change" listener="#{navigator.navigate}" />
</p:selectOneMenu>

Managed bean:

public void navigate() {
    FacesContext context = FacesContext.getCurrentInstance();
     NavigationHandler navigationHandler = context.getApplication()
            .getNavigationHandler();

    navigationHandler.handleNavigation(context, null, outcome
            + "?faces-redirect=true");
}

I have an issue where if I leave the page open for a very long time (maybe a few hours) the ajax navigation seems to stop working. Is there some kind of timeout?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
DD.
  • 21,498
  • 52
  • 157
  • 246
  • 1
    It's session timeout. And it's not only ajax requests, every type of requests becomes invalid until you re-access to the page. – Luiggi Mendoza Feb 25 '13 at 23:09
  • How do you cope with this? Will form submit not work either? – DD. Feb 26 '13 at 10:52
  • This problem will go if you use the approach as proposed in this answer on your previous question: http://stackoverflow.com/questions/15008487/jsf-selectonemenu-navigation – BalusC Feb 26 '13 at 11:52
  • I couldn't use that as I need it to render properly in the iphone using the native – DD. Feb 26 '13 at 15:33
  • @BalusC does the timeout issue only happen with Ajax? If I have a submit button will that work? – DD. Feb 27 '13 at 00:14
  • No, you're basically getting a `ViewExpiredException`, but not dealing with it in any way in case of ajax requests. See also http://stackoverflow.com/questions/3642919/javax-faces-application-viewexpiredexception-view-could-not-be-restored/3642969#3642969 and http://stackoverflow.com/questions/11203195/session-timeout-and-viewexpiredexception-handling-on-jsf-primefaces-ajax-request – BalusC Feb 27 '13 at 00:26

1 Answers1

1

Instead of using ajax navigation use the following:

<p:selectOneMenu value="#{navigator.outcome}" onchange="window.location =this.options[this.selectedIndex].value">                      
    <f:selectItem itemLabel="Select page..." />
    <f:selectItem itemValue="page1" itemLabel="Page 1" />
    <f:selectItem itemValue="page2" itemLabel="Page 2" />
    <f:selectItem itemValue="page3" itemLabel="Page 3" />

</p:selectOneMenu>

This works even if the session times out.

DD.
  • 21,498
  • 52
  • 157
  • 246