如何:使用 jsp2/facelets/templateing 进行部分 Rage 渲染,并仅通过菜单驱动主要内容刷新?

发布于 2024-12-07 05:24:49 字数 1733 浏览 2 评论 0原文

我在堆栈溢出上找到了 BalusC(urs 的忠实粉丝)和其他人的一些帖子,但还没有找到解决方案,这似乎是许多人都希望能够做到的事情。

如果我有这样的facelets/模板结构,则左侧导航 带有驱动主要内容区域中显示的内容的链接,但没有执行 完整的页面刷新,我只想更新主要区域,我该怎么做?

-------------------------------------
| link1  |  show content for link1   |
| link2  |  when link1 is clicked    |
| link2  |  in left navigation area  |
|        |                           |
-------------------------------------

我看到 primefaces 展示柜在单击左侧的菜单项时会刷新整个页面,奇怪的是,richfaces4 展示柜却没有刷新,尽管我正在查看代码,但还无法理解。有没有一个例子可以告诉我如何做到这一点?

这是我的代码

uiTemplate.xhtml (主模板),

<div>
        <div id="left">
            <ui:include src="navigationMenu.xhtml"/> 
        </div>

        <div id="center_content" class="center_content">
            <ui:insert name="center_content" />
        </div>
</div>

然后我的 navigationMenu.xhtml 看起来像

<ui:composition>
        <rich:collapsiblePanel header="ClickMe" switchType="client">                   
            <h:link outcome="page1" value="goto page1" /><br />
            <h:link outcome="page2" value="goto page2" /><br />
            <h:link outcome="page3" value="goto page3" /><br />
        </rich:collapsiblePanel>
</ui:composition>

以及将出现在中心内容区域中的页面之一,希望已加载 无需完全刷新所有部分。

我想我需要一些 f:ajax 标签或使用 h:commandLink 来获取上面的这些链接,但还没有找到好的 例子。我看到很多关于 Mojarra 2.1.x 修复动态包含的帖子,但是 不确定与此相关,除非这是实现此目的的唯一方法。

第1页.xhtml

<ui:composition template="./uiTemplate.xhtml">
        <ui:define name="center_content">
             page 1 content
        </ui:define>
</ui:composition>

I found some posts by BalusC (big fan of urs) and others here on stack overflow and haven't found the solution, which would seem like something many would want to be able to do.

If I have a facelets/templating structure like this, a left navigation
with links that drive what gets shown in main content area, but without doing
a complete page refresh, I just want the main area to update, how do I do this?

-------------------------------------
| link1  |  show content for link1   |
| link2  |  when link1 is clicked    |
| link2  |  in left navigation area  |
|        |                           |
-------------------------------------

I see the primefaces showcase does a whole page refresh when clicking menu items on left, and oddly enough, the richfaces4 showcase does not, although I am looking at the code can't understand just yet. is there a example out there that can show me how to do this?

here is my code

uiTemplate.xhtml (main template)

<div>
        <div id="left">
            <ui:include src="navigationMenu.xhtml"/> 
        </div>

        <div id="center_content" class="center_content">
            <ui:insert name="center_content" />
        </div>
</div>

then my navigationMenu.xhtml looks like

<ui:composition>
        <rich:collapsiblePanel header="ClickMe" switchType="client">                   
            <h:link outcome="page1" value="goto page1" /><br />
            <h:link outcome="page2" value="goto page2" /><br />
            <h:link outcome="page3" value="goto page3" /><br />
        </rich:collapsiblePanel>
</ui:composition>

and one of the pages which will appear in center content area, hopefully loaded
without a complete refresh of all sections.

I would think I am going to need some
f:ajax tag or use h:commandLink for these links above but just haven't found a good
example. I see a bunch posts about Mojarra 2.1.x fixing dynamic includes but
not sure that is related to this, unless that's is the only way to accomplish this.

page1.xhtml

<ui:composition template="./uiTemplate.xhtml">
        <ui:define name="center_content">
             page 1 content
        </ui:define>
</ui:composition>

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

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

发布评论

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

评论(1

歌入人心 2024-12-14 05:24:49

我想出了如何让某些东西正常工作,但是,我还没有做太多测试,比如添加
除了 a4j:commandLink 元素之外,导航表单中还有更多组件。我当前的导航部分仅使用 ajx 请求中的新内容更新中心内容,从而不进行完整的页面刷新,没有什么详细说明,这是我的 navigationMenu.xhtml 文件

<ui:composition>
     <h:form>             
        <rich:collapsiblePanel header="Carriers" switchType="client">                   
            <a4j:commandLink  action="page1" value="goto page1.xhtml" render=":centerContentDiv"/><br />
            <a4j:commandLink  action="page2" value="goto page2.xhtml" render=":centerContentDiv"/><br />
        </rich:collapsiblePanel>
     </h:form>

,然后是我的 uiTemplate.xhtml,这是我的主模板
其中有一个像这样的片段,

<div>
        <div id="left">
            <ui:include src="navigationMenu.xhtml"/> 
        </div>

            <h:panelGroup id="centerContentDiv" layout="block"> 
                <ui:insert name="center_content" />
            </h:panelGroup>

    </div>

我确实注意到似乎有点奇怪,即使在我非常小的测试应用程序中也是如此。
单击链接时我必须非常谨慎,否则它似乎会忽略我

我想我需要添加来自 primefaces 的面孔才能看到
如果它告诉我有关正在发生的事情的任何信息,

我希望这可以帮助那里的人

*** 后续 *****

作为后续,经过一些测试,如果随后包含的中心内容
包含表单,提交这些表单似乎仅在第二次单击命令链接或命令按钮时发生。表单未嵌套,这是表单无法正确提交的常见原因 BalusC 评论此处。我添加了facetraces,它确实到达了服务器,但从恢复视图跳转到渲染响应,第二次单击它经历了所有阶段。

导航 uiComposition 具有 ah:form 且中心内容 uiComposition 具有 ah:form 的事实导致了问题。我知道这一点是因为如果我删除导航 uiComposition,并直接通过输入 URL 加载中心内容,那么它的表单会在第一次单击时正确提交。我认为 BalusC 在 中提到了有关此内容的内容关于部分页面渲染的帖子,但该帖子中没有完整的示例,我有点难以理解。我认为这将是一个常见任务,很多人都想实现,所以我将继续挖掘。

I figured out how to get something working, however, I have not done much testing, like adding
more components into the navigation form other than a4j:commandLink elements. my current navigation section merely updates the center content with new content in a ajx request thereby not doing a complete page refresh, nothing elaborate, here is my navigationMenu.xhtml file

<ui:composition>
     <h:form>             
        <rich:collapsiblePanel header="Carriers" switchType="client">                   
            <a4j:commandLink  action="page1" value="goto page1.xhtml" render=":centerContentDiv"/><br />
            <a4j:commandLink  action="page2" value="goto page2.xhtml" render=":centerContentDiv"/><br />
        </rich:collapsiblePanel>
     </h:form>

and then my uiTemplate.xhtml which is my master template
has a snippet in it like this

<div>
        <div id="left">
            <ui:include src="navigationMenu.xhtml"/> 
        </div>

            <h:panelGroup id="centerContentDiv" layout="block"> 
                <ui:insert name="center_content" />
            </h:panelGroup>

    </div>

I do notice there seems to be a bit of a oddity, even in my really small test app.
I have to be real deliberate when clicking the links or it seems to ignore me

I guess i need to add facestraces from primefaces to see
if it tells me anything about whats happening

I hope this helps someone out there

*** followup *****

As a followup, after some testing, if the included center content subsequently
contains form(s), submitting those form(s) seems to only happen on second click of a commandLink or commandButton. The forms are not nested which is a common reason a form don't submit correctly BalusC comments here. I added facestraces and it does hit the server but jumps from restore view to render response, 2nd click it goes through all phases.

The fact that the navigation uiComposition has a h:form and the center content uiComposition has a h:form is causing issues. I know this because if I remove the navigation uiComposition, and just load the center content directly via typed in URL, then it's form submits correctly on first click. I think BalusC was referring to something about this in post on partial page rendering but without a complete example in that post, it was a bit hard for me to follow. This would be a common task I would assume many would want to implement, so I'll keep digging.

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