从 web 应用程序更新 url 栏以表示当前状态
我基本上想做杰森要求的事情 这里
在一句话中,我希望 url 栏代表 AJAX 应用程序的状态,以便我可以为其添加书签,并允许用户使用后退/前进按钮返回到之前的状态在浏览器中。
对我来说,不同之处(据 Jason 询问)是我使用的是 JSF 2.0。 我读到 JSF 2.0 添加了使用 get 的功能,但我不确定使用它的正确方法是什么。
感谢您的帮助。
进一步说明
如果我理解正确,为了能够在 AJAX Web 应用程序中为特定状态添加书签,我将必须使用 location.hash。我说得对吗?我正在尝试实现类似 gmail 的行为,即虽然应用程序已完成 AJAX 化并且不会发生重定向,但我仍然可以使用后退/前进和书签(这就是为什么我希望 URL 栏从AJAX 应用程序本身而不是通过重定向)
更新
刚刚找到这个类似的问题
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,这与维护 Ajax 状态不同。通常是通过片段标识符(URL 中以
#
开头的部分,也称为 hashbang)发生的。 JSF 不为此提供内置组件/功能。到目前为止我还没有看到一个组件库可以做到这一点。但是,您可能会发现 这个答案对于开始使用 JSF 中的本地哈希片段处理器很有用。至于使用 GET 请求,只需使用
、
甚至来创建获取链接。您可以通过
在h:
组件中提供请求参数。例如,在
product/edit.xhtml
页面中,您可以定义要在 GET 请求上设置的参数和执行的操作在与
product/edit.xhtml
关联的请求或视图作用域 bean 中> 页面 - 在此示例中#{productEditor}
- 您只需定义属性和侦听器方法。在模型中收集、转换、验证和更新所有属性后,将执行侦听器方法。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 theh:
components by<f:param>
. E.g.In the
product/edit.xhtml
page you can define parameters to set and actions to execute upon a GET requestIn 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.通常您会使用 AJAX 来阻止完整的页面刷新。 AFAIK 如果您更改基本 uri,所有当前浏览器都会发出页面刷新问题。因此,您必须按照您提供的问题中的建议使用哈希部分。
我们遇到了类似的问题并做了类似的事情:
Normally you'd use AJAX to prevent complete page refreshes. AFAIK all current browsers would issue a page refresh if you change the base uri. Thus you would have to use the hash part as suggested in the question you provided.
We had a similar problem and did something like this: