3

If I place, for instance, the following component and click it, it behaves as expected:

<h:commandLink value="Click me" action="anotherPage.jsf" />

But if I use Ajax:

<h:commandLink value="Click me" action="anotherPage.jsf"><f:ajax /></h:commandLink>

It doesn't navigate to the other page. Am I missing something? Isn't this supposed to work?

Another issue is that, when I click a button that is using ajax after session timeout, the application redirects to the login page but it doesn't load css files.

Any ideas?

Kind regards,

Carlos Ferreira

Carlos Ferreira
  • 565
  • 1
  • 8
  • 15

3 Answers3

8

You can do it if you send a redirect.

action="anotherPage.jsf?faces-redirect=true"

However, I completely fail to see the point/benefit of navigating using Ajax like that.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Well, I'm just exploring my options. I was trying to find a workaround for the POST/back button problem. – Carlos Ferreira Mar 23 '11 at 15:04
  • @BalusC Hi BalusC. Just found this [page](http://weblogs.java.net/blog/driscoll/archive/2009/05/redirecting_fro.html). Is your solution a kind of shortcut for the solution presented there? – Matt Handy Mar 23 '11 at 15:04
  • @Matt: If no action method needs to be invoked, yes. Otherwise you could also just do `return "anotherPage?faces-redirect=true";` at end of the action method. Jim's solution is overcomplicated for internal pages. – BalusC Mar 23 '11 at 15:07
  • 1
    @Carlos: you need to post a question about the problem instead of a question about a solution for which you thought that it is the right solution. In this particular case you likely need `` instead of ``. Using POST for page-to-page navigation is indeed a bad idea. See also http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink – BalusC Mar 23 '11 at 15:08
  • @BalusC You're probably right, but the problem I was having was with the ajax event :) – Carlos Ferreira Mar 23 '11 at 15:12
  • @BalusC I've no other option. The application has confirmation screens for all the forms. – Carlos Ferreira Mar 23 '11 at 15:14
1

From my understanding ajax is used to update components of the current page and not to navigate to other pages.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
0

If you have lots of ajax requests on your page then ajaxifying the command button's request mean's that all other validations (from other ajax requests) on the page will complete before navigation to the next page. Otherwise without the ajax request for the button the http request that it generates will blow away these other requests and just navigate directly to the next page without waiting for them to complete.

bakeha
  • 1
  • 1