Javascript 禁用时 Ajax 回退

发布于 2024-12-24 19:10:00 字数 1266 浏览 2 评论 0原文

问题:
i) 在 JSF2 应用程序中,我想创建一个带有选项卡控件的页面,当用户单击选项卡时,下面的面板内容将通过 ajax 调用从服务器中的 xhtml 文件加载。
ii) 我希望它支持优雅降级(当禁用 Javascript 时),以便在单击选项卡时,会触发 HTTP 请求,并加载新页面...或者相反,通过渐进增强。

部分解决方案: i)我想我可以通过 BalusC 在 How to ajax jsf 中发布的代码示例来完成此任务2 输出链接
:-

<h:form>
<f:ajax render=":include">
    <h:commandLink value="Home" action="#{menuManager.setPage('home')}" /><br />
    <h:commandLink value="FAQ" action="#{menuManager.setPage('faq')}" /><br />
    <h:commandLink value="Contact" action="#{menuManager.setPage('contact')}" /><br />
</f:ajax>

</h:form>
<h:panelGroup id="include">
    <ui:include src="#{menuManager.page}.xhtml" />
</h:panelGroup>

问题
我如何扩展它来解决问题(ii)或者还有其他完全不同的方法吗?我想也许我可以用无脚本来实现这一点,但不知道如何实现!

编辑:可能的解决方案 - 尚未验证
即使 ajax 被禁用,上面的代码也应该可以工作;它应该只通过 HTTP 工作,根据 http://www .laliluna.de/articles/posts/jsf-2-evaluation-test.html :)
优雅的!我会尝试一下。

Problem:
i) In a JSF2 application, I want to create a page with a tab control, where, when the user clicks on a tab, the contents for the panel below is loaded from an xhtml file in the server through an ajax call.
ii) I want this to support graceful degradation (when Javascript is disabled), so that upon clicking the tab, an HTTP request is fired, and a new page is loaded...or the other way round, through progressive enhancement.

Partial solutions:
i) I guess I can accomplish this through the code example posted by BalusC in How to ajax jsf 2 outputLink
:-

<h:form>
<f:ajax render=":include">
    <h:commandLink value="Home" action="#{menuManager.setPage('home')}" /><br />
    <h:commandLink value="FAQ" action="#{menuManager.setPage('faq')}" /><br />
    <h:commandLink value="Contact" action="#{menuManager.setPage('contact')}" /><br />
</f:ajax>

</h:form>
<h:panelGroup id="include">
    <ui:include src="#{menuManager.page}.xhtml" />
</h:panelGroup>

Question
How can I extend this to solve problem (ii) Or is there any other completely different method? I think maybe I could achieve this with a noscript, but can't figure out how!

EDIT: Possible solution - yet to verify:
The above code should work even if ajax is disabled; it should just work through HTTP, according to http://www.laliluna.de/articles/posts/jsf-2-evaluation-test.html :)
Elegant! I'll try it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-12-31 19:10:00

如果你使用 而不是 ,那么当 JS 被禁用时它会正常工作。无论如何,命令链接都需要 JS 才能提交“隐藏​​”POST 表单,无论是否使用ajax。如果有必要,您可以添加一些 CSS 以使命令按钮看起来像链接(例如删除边框、背景、插图等)。

作为一种完全不同的替代方案,通过使用 将页面作为请求参数或路径信息来使它们发出 GET 请求,使用 jQuery.load() 来不显眼地获取包含页面、提取相关部分并包含在 HTML DOM 树中。

If you use <h:commandButton> instead of <h:commandLink>, then it will work just fine when JS is disabled. The command links require JS anyway in order to submit a "hidden" POST form, ajaxified or not. You could if necessary throw in some CSS to make the command buttons to look like links (e.g. remove border, background, inset, etc).

As a completely different alternative, make them GET requests anyway by using <h:outputLink> or <h:link> with the page as a request parameter or pathinfo and use jQuery.load() instead to unobtrusively obtain the include page, extract the relevant portion and include in the HTML DOM tree.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文