Updating url with ajax JSF request

I use JSF 2 with PrettyFaces, as well as the <h:link> and <f:param> tags to get the bookmark pages (great to finally forget about all these POST requests in the JSF application).

However, some of these links only change a small part of the page (mainly when the user remains in one view), so it’s better to send ajax requests. However, <f:ajax> cannot be used with <h:link> , just <h:commandlink> . I can send parameters in many ways using the command line, but in this case the URL remains unchanged after the request. Thus, it becomes incompatible with the contents of the page, and it is not updated.

I have seen sites that use links that send a mixture of GET and ajax requests (pointing to a new URL when changing the page using ajax), but so far I have not found any solution.

Is it possible to somehow update the url using jsf after the ajax request is complete (or when the user clicks)? Or do I need to use some external JS library?

EDIT . The JS library that is needed here is the new JavaScript History API. Additional Information. I think JSF is not using this API at this time. But I'm still interested in this issue from the perspective of the JSF developer.

Also, is there any future JSF release planned? Combining <f:ajax> with <h:link> would be the perfect solution.

+7
source share
1 answer

<f:ajax> has onevent attribute. It takes the name of the javascript function, which will be called after the completion of the ajax request . Thus, you can add the js function, which will navigate to the desired URL after the ajax call ends. Something like:

  <h:commandLink id="testButton" value="Test"> <f:ajax event="action" execute="@form" render="@none" listener="#{myBean.testButtonClickedHandler}" onevent="navigate"/> </h:commandLink> <script type="text/javascript"> function navigate() { window.location.href = "required url"; } </script> 
-one
source

All Articles