导航时部分页面更新(PrimeFaces ajax) [英] Partial page update when navigating (PrimeFaces ajax)

查看:30
本文介绍了导航时部分页面更新(PrimeFaces ajax)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 facelets 模板完成了一个基本的 JSF 应用程序.我的模板如下:

<h:头><!-- CSS 样式表的链接... --><title><ui:insert name="title"/>- FManager</h:head><h:body><div id="包装器"><div id="标题"><b>FManager</b>应用程序

<div id="内容"><p:grow id="growl"/><ui:insert name="content">示例内容.</ui:insert>

<div id="footer">使用 JSF 和 Primefaces 制作</div></h:body>

然后我有一个主页(如下所示)导航到第二页.两个页面都使用上面的模板.

<ui:define name="title">主页</ui:define><ui:define name="content"><h2>欢迎来到<b>FManager</b>应用<h:形式><p>点击下面的按钮创建第一个条目!</p><p:commandButton value="Create entry" action="create"/></h:form></ui:define></ui:composition>

如果我在 faces-config.xml 中使用 ,它会导航,但会重新加载 完整 页面.我的问题是:

有没有办法从一个页面导航到另一个页面,只更新模板的 <ui:insert> 部分?(同时离开页面的其余部分完好无损)

谢谢!

解决方案

您可以通过 ajax 重新加载内容,但 URL 将保持不变.如果您负担得起,请按如下方式更新代码:

template.xhtml中,替换

<小时>

somepage.xhtml中,替换

<p:commandButton value="Create entry" action="create"/>

<p:commandButton value="Create entry" action="create" update=":content"/>

<小时>

终于去掉<redirect/>(其实更喜欢摆脱 所有导航案例,因为它们使 faces-config.xml 文件膨胀).顺便说一下,也可以在结果中指定重定向,如 action="create?faces-redirect=true".

这只是不更新​​</code>.但是,您可以使用简单的 JavaScript 代码行来做到这一点.</p><p>I have done a basic JSF app, using facelets templates. My template is as follows:</p><pre><code><html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <!-- Links to CSS stylesheets... --> <title><ui:insert name="title" /> - FManager</title> </h:head> <h:body> <div id="wrapper"> <div id="header"> <b>FManager</b> Application </div> <div id="content"> <p:growl id="growl" /> <ui:insert name="content"> Sample content. </ui:insert> </div> </div> <div id="footer">Made using JSF and Primefaces</div> </h:body> </html> </code></pre><p>And then I have a <em>Main Page</em> (shown below) that navigates to a <em>Second Page</em>. Both pages use the template above.</p><pre><code><ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui" template="./template.xhtml"> <ui:define name="title">Main page</ui:define> <ui:define name="content"> <h2>Welcome to the <b>FManager</b> application</h2> <h:form> <p>Click the button below to create the first entry!</p> <p:commandButton value="Create entry" action="create" /> </h:form> </ui:define> </ui:composition> </code></pre><p>If I use <code><redirect/></code> in faces-config.xml, it navigates, but the <strong>full</strong> page is reloaded. My question is:</p> <p><b>Is there a way to navigate from a page to another updating ONLY the <code><ui:insert></code> sections of the template?</b> (While leaving the rest of the page intact)</p> <p>Thanks!</p><div class="h2_lin"> 解决方案 </div><p>You can reload content by ajax, but URL will stay the same. If you can afford that, update the code as follows:</p> <p>In <code>template.xhtml</code>, replace</p><pre><code><div id="content"> </code></pre><p>by</p><pre><code><h:panelGroup id="content" layout="block"> </code></pre><p> <hr> <p>And in <code>somepage.xhtml</code>, replace</p><pre><code><p:commandButton value="Create entry" action="create" /> </code></pre><p>by</p><pre><code><p:commandButton value="Create entry" action="create" update=":content" /> </code></pre><p> <hr> <p>Finally get rid of the <code><redirect /></code> (actually, prefer to <a href="http://blogs.oracle.com/rlubke/entry/faces_config_xml_we_don" rel="nofollow">get rid</a> of all navigation cases since they make the <code>faces-config.xml</code> file bloated). A redirect can by the way also be specified in the outcome as in <code>action="create?faces-redirect=true"</code>.</p> <p>This does only not update the <code><title></code>. You could however do that with a simple JavaScript line.</p> <p>这篇关于导航时部分页面更新(PrimeFaces ajax)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!</p> </div> <div class="arc-body-main-more"> <span onclick="unlockarc('2746701');">查看全文</span> </div> </div> <div> </div> <div class="wwads-cn wwads-horizontal" data-id="166" style="max-width:100%;border: 4px solid #666;"></div> </div> </article> <div id="arc-ad-2" class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="widget bgwhite radius-1 mb-1 shadow widget-rel"> <h5>相关文章</h5> <ul> <li> <a target="_blank" title="导航时的部分页面更新(PrimeFaces AJAX)" href="/48982.html"> 导航时的部分页面更新(PrimeFaces AJAX); </a> </li> <li> <a target="_blank" title="使用更新面板部分页面更新" href="/269178.html"> 使用更新面板部分页面更新; </a> </li> <li> <a target="_blank" title="如何使用Sitecore使用Ajax进行部分页面更新?" href="/2879384.html"> 如何使用Sitecore使用Ajax进行部分页面更新?; </a> </li> <li> <a target="_blank" title="PagedList.MVC 中的 Ajax 分页使用部分页面" href="/2620300.html"> PagedList.MVC 中的 Ajax 分页使用部分页面; </a> </li> <li> <a target="_blank" title="JSF Primefaces Ajax更新" href="/2154318.html"> JSF Primefaces Ajax更新; </a> </li> <li> <a target="_blank" title="JSF Primefaces selectonemenu 页面导航" href="/2797024.html"> JSF Primefaces selectonemenu 页面导航; </a> </li> <li> <a target="_blank" title="JSF Primefaces selectonemenu页面导航" href="/1502485.html"> JSF Primefaces selectonemenu页面导航; </a> </li> <li> <a target="_blank" title="使用ajax和java脚本刷新部分页面" href="/1301221.html"> 使用ajax和java脚本刷新部分页面; </a> </li> <li> <a target="_blank" title="如何使用jQuery进行部分页面更新?" href="/1482280.html"> 如何使用jQuery进行部分页面更新?; </a> </li> <li> <a target="_blank" title="MVC3中的部分页面更新" href="/1381541.html"> MVC3中的部分页面更新; </a> </li> <li> <a target="_blank" title="如何使用 jQuery 进行部分页面更新?" href="/2800641.html"> 如何使用 jQuery 进行部分页面更新?; </a> </li> <li> <a target="_blank" title="PrimeFaces commandButton 不导航或更新" href="/2692733.html"> PrimeFaces commandButton 不导航或更新; </a> </li> <li> <a target="_blank" title="PrimeFaces commandButton不会导航或更新" href="/1501641.html"> PrimeFaces commandButton不会导航或更新; </a> </li> <li> <a target="_blank" title="部分页面渲染" href="/1363697.html"> 部分页面渲染; </a> </li> <li> <a target="_blank" title="部分页面刷新" href="/1134399.html"> 部分页面刷新; </a> </li> <li> <a target="_blank" title="页面使用Ajax没有jQuery的更新部分" href="/60845.html"> 页面使用Ajax没有jQuery的更新部分; </a> </li> <li> <a target="_blank" title="Jsoup获取部分页面" href="/1517540.html"> Jsoup获取部分页面; </a> </li> <li> <a target="_blank" title="刷新部分页面(div)" href="/860706.html"> 刷新部分页面(div); </a> </li> <li> <a target="_blank" title="部分页面被引用" href="/1363397.html"> 部分页面被引用; </a> </li> <li> <a target="_blank" title="URL中存在分页时如何导航到其他页面" href="/1517770.html"> URL中存在分页时如何导航到其他页面; </a> </li> <li> <a target="_blank" title="Ajax在Primefaces中更新JavaScript脚本" href="/2165101.html"> Ajax在Primefaces中更新JavaScript脚本; </a> </li> <li> <a target="_blank" title="如何在Datagrid中导航页面(分页导航)" href="/1240885.html"> 如何在Datagrid中导航页面(分页导航); </a> </li> <li> <a target="_blank" title="部分页面卷曲动画" href="/588543.html"> 部分页面卷曲动画; </a> </li> <li> <a target="_blank" title="在asp.net中使用AJAX进行部分页面刷新" href="/1322279.html"> 在asp.net中使用AJAX进行部分页面刷新; </a> </li> <li> <a target="_blank" title="ajax部分页面渲染可以应用于html select标签吗?" href="/1462662.html"> ajax部分页面渲染可以应用于html select标签吗?; </a> </li> </ul> </div> <div class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="side"> <div class="widget widget-side bgwhite mb-1 shadow"> <h5>前端开发最新文章</h5> <ul> <li> <a target="_blank" title="为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?" href="/1996151.html"> 为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?; </a> </li> <li> <a target="_blank" title="错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接" href="/749568.html"> 错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接; </a> </li> <li> <a target="_blank" title="如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?" href="/1009885.html"> 如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?; </a> </li> <li> <a target="_blank" title="如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?" href="/884909.html"> 如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?; </a> </li> <li> <a target="_blank" title="警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件" href="/818517.html"> 警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件; </a> </li> <li> <a target="_blank" title="如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?" href="/343346.html"> 如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?; </a> </li> <li> <a target="_blank" title="此请求已被阻止;内容必须通过HTTPS提供" href="/886417.html"> 此请求已被阻止;内容必须通过HTTPS提供; </a> </li> <li> <a target="_blank" title="资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关)" href="/562873.html"> 资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关); </a> </li> <li> <a target="_blank" title="通过HTTPS加载页面但请求不安全的XMLHttpRequest端点" href="/885901.html"> 通过HTTPS加载页面但请求不安全的XMLHttpRequest端点; </a> </li> <li> <a target="_blank" title="拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。" href="/47347.html"> 拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。; </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门教程 </h5> <ul> <li> <a target="_blank" title="Java教程" href="/OnLineTutorial/java/index.html"> Java教程 </a> </li> <li> <a target="_blank" title="Apache ANT 教程" href="/OnLineTutorial/ant/index.html"> Apache ANT 教程 </a> </li> <li> <a target="_blank" title="Kali Linux教程" href="/OnLineTutorial/kali_linux/index.html"> Kali Linux教程 </a> </li> <li> <a target="_blank" title="JavaScript教程" href="/OnLineTutorial/javascript/index.html"> JavaScript教程 </a> </li> <li> <a target="_blank" title="JavaFx教程" href="/OnLineTutorial/javafx/index.html"> JavaFx教程 </a> </li> <li> <a target="_blank" title="MFC 教程" href="/OnLineTutorial/mfc/index.html"> MFC 教程 </a> </li> <li> <a target="_blank" title="Apache HTTP客户端教程" href="/OnLineTutorial/apache_httpclient/index.html"> Apache HTTP客户端教程 </a> </li> <li> <a target="_blank" title="Microsoft Visio 教程" href="/OnLineTutorial/microsoft_visio/index.html"> Microsoft Visio 教程 </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门工具 </h5> <ul> <li> <a target="_blank" title="Java 在线工具" href="/Onlinetools/details/4"> Java 在线工具 </a> </li> <li> <a target="_blank" title="C(GCC) 在线工具" href="/Onlinetools/details/6"> C(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="PHP 在线工具" href="/Onlinetools/details/8"> PHP 在线工具 </a> </li> <li> <a target="_blank" title="C# 在线工具" href="/Onlinetools/details/1"> C# 在线工具 </a> </li> <li> <a target="_blank" title="Python 在线工具" href="/Onlinetools/details/5"> Python 在线工具 </a> </li> <li> <a target="_blank" title="MySQL 在线工具" href="/Onlinetools/Dbdetails/33"> MySQL 在线工具 </a> </li> <li> <a target="_blank" title="VB.NET 在线工具" href="/Onlinetools/details/2"> VB.NET 在线工具 </a> </li> <li> <a target="_blank" title="Lua 在线工具" href="/Onlinetools/details/14"> Lua 在线工具 </a> </li> <li> <a target="_blank" title="Oracle 在线工具" href="/Onlinetools/Dbdetails/35"> Oracle 在线工具 </a> </li> <li> <a target="_blank" title="C++(GCC) 在线工具" href="/Onlinetools/details/7"> C++(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="Go 在线工具" href="/Onlinetools/details/20"> Go 在线工具 </a> </li> <li> <a target="_blank" title="Fortran 在线工具" href="/Onlinetools/details/45"> Fortran 在线工具 </a> </li> </ul> </div> </div> </div> <script type="text/javascript">var eskeys = '导航,时,部分,页面,更新,primefaces,ajax'; var cat = 'cc';';//qianduan</script> </div> <div id="pop" onclick="pophide();"> <div id="pop_body" onclick="event.stopPropagation();"> <h6 class="flex flex101"> 登录 <span onclick="pophide();">关闭</span> </h6> <div class="pd-1"> <div class="wxtip center"> <span>扫码关注<em>1秒</em>登录</span> </div> <div class="center"> <img id="qr" src="https://huajiakeji.com/Content/Images/qrydx.jpg" alt="" style="width:150px;height:150px;" /> </div> <div style="margin-top:10px;display:flex;justify-content: center;"> <input type="text" placeholder="输入验证码" id="txtcode" autocomplete="off" /> <input id="btngo" type="button" onclick="chk()" value="GO" /> </div> <div class="center" style="margin: 4px; font-size: .8rem; color: #f60;"> 发送“验证码”获取 <em style="padding: 0 .5rem;">|</em> <span style="color: #01a05c;">15天全站免登陆</span> </div> <div id="chkinfo" class="tip"></div> </div> </div> </div> <script type="text/javascript" src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/highlight.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/base.js?v=0.22"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/tui.js?v=0.11"></script> <footer class="footer"> <div class="container"> <div class="flink mb-1"> 友情链接: <a href="https://www.it1352.com/" target="_blank">IT屋</a> <a href="https://huajiakeji.com/" target="_blank">Chrome插件</a> <a href="https://www.cnplugins.com/" target="_blank">谷歌浏览器插件</a> </div> <section class="copyright-section"> <a href="https://www.it1352.com" title="IT屋-程序员软件开发技术分享社区">IT屋</a> ©2016-2022 <a href="http://www.beian.miit.gov.cn/" target="_blank">琼ICP备2021000895号-1</a> <a href="/sitemap.html" target="_blank" title="站点地图">站点地图</a> <a href="/Home/Tags" target="_blank" title="站点标签">站点标签</a> <a target="_blank" alt="sitemap" href="/sitemap.xml">SiteMap</a> <a href="/1155981.html" title="IT屋-免责申明"><免责申明></a> 本站内容来源互联网,如果侵犯您的权益请联系我们删除. </section> <!--统计代码--> <script type="text/javascript"> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?0c3a090f7b3c4ad458ac1296cb5cc779"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript"> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </div> </footer> </body> </html>