Updating url string from webapp to represent current state

I would basically do what Jason asked here

In one sentence, I would like the url string to represent the state of the AJAX application so that I can enable its bookmarking and also allow the user to return to the previous state using the back / forward buttons in the browser.

The difference for me (according to Jason) is that I use JSF 2.0. I read that JSF 2.0 added the ability to use get, but I'm not sure which is the right way to use this.

Thanks for the help.

Further refinement

If I understand correctly, in order to be able to bookmark certain states in an AJAX web application, I will have to use location.hash. I'm right? I am trying to achieve a behavior similar to gmail in the sense that although the application is AJAXified terminated and no redirects occur, I can still use Back / Forward and the bookmark (And so I would like the URL bar to be updated with the application AJAX, not redirection)

Update

Just found this similar question

+4
source share
2 answers

The difference for me (according to Jason) is that I use JSF 2.0. I read that JSF 2.0 added the ability to use get, but I'm not sure which is the right way to use this.

Please note that this is not the same as maintaining Ajax state. This usually happens with fragment identifiers (the part starting with # in the URL, also known as hashbang). JSF does not offer built-in components / functions for this. As far as I have not seen the component library that does this. However, you can find this answer to get started with the fragmented hash fragment processor in JSF.

Regarding the use of GET requests, just use <h:link> , <h:outputLink> or even <a> to create GET links. You can specify query parameters in h: components on <f:param> . For instance.

 <h:link value="Edit product" outcome="product/edit"> <f:param name="id" value="#{product.id}" /> </h:link> 

On the product/edit.xhtml you can define parameters for installation and actions for execution upon request by GET

 <f:metadata> <f:viewParam name="id" value="#{productEditor.id}" /> <f:event type="preRenderView" listener="#{productEditor.init}" /> </f:metadata> 

In the request or presentation area limited by the bean associated with the product/edit.xhtml - in this example #{productEditor} -, you simply define the properties and method of the listener. The listener method will be executed after all the properties are collected, converted, validated and updated in the model.

 private Long id; private Product product; public void init() { product = productService.find(id); } 
+3
source

Usually you should use AJAX to prevent a full page refresh. AFAIK all current browsers will refresh the page if you change the base uri. Therefore, you will have to use the hash part as suggested in the question you provided.

We had a similar problem, and we did something like this:

  • We decided that users could not add the URL.
  • For URLs that should be unique / bookmarkable, we used different links that cause redirection. These URLs are listed in the sitemap.
  • For feedback with the browser, we added an intermediate page after logging in. On this page there is navigation and redirection to the application. Navigation is saved in the session, and when the server receives a navigation request (which can be returned to the history), the corresponding state is restored. A browser page opens on an intermediate page that issues a redirect along with a server-side navigation request.
0
source

All Articles