JSF2通过Ajax动态加载页面 [英] JSF2 Dynamically loading pages by ajax
问题描述
当我单击JSF2.0中的菜单链接时,我想将页面加载到中央div中.我设置了一个面板菜单,并编写了一个像这样的菜单项.
I want to load pages into a central div when i click my menu links in JSF2.0. I set up a panelmenu and wrote a menu item like this.
<p:menuitem >
<h:commandButton value="Edit Details" action="#{formsBean.changeDisplay(1)}">
<f:ajax render=":editdiv"></f:ajax>
</h:commandButton>
</p:menuitem>
要更新的组件是:
<h:panelGroup id="editdiv" rendered="#{formsBean.edituserdiv}" layout="block">
<ui:include src="edituserdetails.xhtml">
</ui:include>
</h:panelGroup>
函数formsBean.changeDisplay(1)
将edituserdiv
设置为true以显示相应的面板组.
The function formsBean.changeDisplay(1)
sets edituserdiv
to true to show the corresponding panel group.
在包含的页面中,我定义了一个表格.
In the included page i have a form defined.
还在主页中,我调用了一个预渲染功能,将所有div设置为false,以便在第一页加载时不显示任何div.
Also in the main page i call a pre-render function to set all divs to false to show no div on first page load.
问题是,当我单击菜单项时,所包含的页面未包含在内.有指针吗?
The problem is that when i click the menu item the included page is not being included. Any pointers?
推荐答案
问题是因为最初未呈现您的h:panelGroup
,所以AJAX请求无法在生成的代码中找到它,因此无法对其进行更新.将其封装在另一个h:panelGroup
中并进行渲染:
The problem is because initially your h:panelGroup
is not rendered so AJAX request can't find it in generated code, so it can't update it. Encapsulate it in another h:panelGroup
and render it:
<h:panelGroup id="editdivParent" layout="block">
<h:panelGroup id="editdiv" rendered="#{formsBean.edituserdiv}" layout="block">
<ui:include src="edituserdetails.xhtml">
</ui:include>
</h:panelGroup>
</h:panelGroup>
并将f:ajax
更改为:
<f:ajax render=":editdivParent"/>
这篇关于JSF2通过Ajax动态加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!