从Web应用程序更新地址栏重新present当前状态 [英] Updating the url bar from the webapp to represent the current state

查看:70
本文介绍了从Web应用程序更新地址栏重新present当前状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基本上做什么,杰森要求<一个href="http://stackoverflow.com/questions/1457/modify-address-bar-url-in-ajax-app-to-match-current-state">here

在一个句子,我想地址栏重新present的AJAX应用程序的状态,这样我可以允许书签,以及允许用户通过使用返回previous状态前进/后退按钮在浏览器中。

我的差值(从什么杰森问)是我使用JSF 2.0。 我读过,JSF 2.0中添加使用获得的能力,但我不知道使用该怎样才是正确的方式。

感谢您的帮助。

进一步明确

如果我理解正确的话,才能够在AJAX Web应用书签特定状态,我将不得不使用的location.hash。我对么?我想实现在这个意义上一个Gmail般的行为,而应用程序是完全Ajax化,没有重定向发生,我仍然可以使用后退/前进和书签(这就是为什么我想地址栏从更新在AJAX应用程序本身,而不是通过重定向)。

更新

刚刚发现<一href="http://stackoverflow.com/questions/3475076/retrieve-the-fragment-hash-from-a-url-and-inject-the-values-into-the-bean">this类似的问题

解决方案
  

对我来说,差(从什么杰森问)是我使用JSF 2.0。我读过,JSF 2.0中添加使用获得的能力,但我不知道使用该怎样才是正确的方式。

请注意,这是不一样的保持阿贾克斯状态。它通常由片段标识符发生(部分开头的URL,也被称为hashbang)。 JSF没有为此提供了内置的组件/功能。据我还没有看到这确实是一个组件库。然而,你可能会发现<一href="http://stackoverflow.com/questions/3475076/retrieve-the-fragment-hash-from-a-url-and-inject-the-values-into-the-bean">this答案有用的开始使用JSF中一个土生土长的哈希代码的处理器。

由于使用GET请求,只需使用&LT; H:链接&GT; &LT; H:outputLink的&GT; 甚至&LT; A&GT; 以创建GET链接。您可以在 H供应请求的参数:组件由&LT; F:参数&GT; 。例如,

 &LT; H:链接的价值=编辑产品的结果=产品/编辑&GT;
    &LT; F:参数名称=ID值=#{product.id}/&GT;
&LT; / H:链接&GT;
 

产品/ edit.xhtml 页面,您可以定义在一个GET请求来执行的参数设定和动作

 &LT; F:元数据&GT;
    &LT; F:viewParam名=ID值=#{productEditor.id}/&GT;
    &LT; F:事件类型=preRenderView监听器=#{productEditor.init}/&GT;
&LT; / F:元数据&GT;
 

在请求或视图范围与产品/ edit.xhtml 页 - 在这个例子关联豆#{productEditor} - ,你刚才定义的属性和监听器方法。侦听器方法将被执行后,所有的属性都被收集,转换,验证和更新的模型。

 专用长ID;
私人产品的产品;

公共无效的init(){
    产物= productService.find(ID);
}
 

I would like to basically do what Jason asked for here

In one sentence, I would like the url bar to represent the state of the AJAX application so that I can allow to bookmark it as well as allow the user to return to the previous state by using the back/forward buttons in the browser.

The difference for me (From what Jason asked) is that I am using JSF 2.0. I've read that JSF 2.0 added the ability to use get, but I am not sure what the correct way to use this.

Thanks for the help.

Further Clarification

If I understand correctly, to be able to bookmark specific states in the AJAX webapp I will have to use the location.hash. Am I correct? I'm trying to achieve a gmail-like behaviour in the sense that, while the app is complete AJAXified and no redirects occur, I can still use Back/Forward and bookmark (And that's why I would like the URL bar to be updated from the AJAX app itself and not through redirection)

Update

Just found this similar question

解决方案

The difference for me (From what Jason asked) is that I am using JSF 2.0. I've read that JSF 2.0 added the ability to use get, but I am not sure what the correct way to use this.

Please note that this is not the same as maintaining the Ajax state. It usually happens by fragment identifiers (the part starting with # in URL, also known as hashbang). JSF doesn't offer builtin components/functionality for this. As far I have also not seen a component library which does that. You may however find this answer useful to get started with a homegrown hash fragment processor in JSF.

As to using GET requests, just use <h:link>, <h:outputLink> or even <a> to create GET links. You can supply request parameters in the h: components by <f:param>. E.g.

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

In the product/edit.xhtml page you can define parameters to set and actions to execute upon a GET request

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

In the request or view scoped bean associated with product/edit.xhtml page -in this example #{productEditor}-, you just define the properties and the listener method. The listener method will be executed after all properties are been gathered, converted, validated and updated in the model.

private Long id;
private Product product;

public void init() {
    product = productService.find(id);
}

这篇关于从Web应用程序更新地址栏重新present当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆