JSF2 Dynamically loading pages by ajax

帅比萌擦擦* 提交于 2019-12-12 10:20:09

问题


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>

The component to be updated is:

<h:panelGroup id="editdiv" rendered="#{formsBean.edituserdiv}" layout="block">
  <ui:include src="edituserdetails.xhtml">

 </ui:include>
 </h:panelGroup>

The function formsBean.changeDisplay(1) sets edituserdiv to true to show the corresponding panel group.

In the included page i have a form defined.

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?


回答1:


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>

And change your f:ajax to:

<f:ajax  render=":editdivParent"/>


来源:https://stackoverflow.com/questions/15412704/jsf2-dynamically-loading-pages-by-ajax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!