我试图“懒惰”#39;丰富的组件。不知何故,我无法在没有页面刷新的情况下进行渲染。我想避免整页刷新。
情况:
基本页面加载:
menuBean.java
private MenuBarComponent getLazyMenuBarComponent() {
if (lazyMenuBar != null) {
return lazyMenuBar;
}
lazyMenuBar = new MainMenuBarLazy(); // no children
return lazyMenuBar;
}
按下“激活”菜单' - 按钮:
page.xhtml
<a4j:region id="main-menu-region">
<h:form id="mainMenu-form">
<rich:dropDownMenu binding="#{menuBarBean.menuBar}"
id="HOOFDMENU"
showEvent="mouseup"
onclick="showMenu();"
styleClass="menu-hdr-btn"
hideDelay="3600000"
showDelay="0"
onshow="onMenuShow();"
/>
<a4j:jsFunction name="fetchMenu" action="#{menuBarBean.fetchMenu}"
render="@region @form HOOFDMENU"> <!-- I THOUGHT THIS SHOULD WORK -->
</a4j:jsFunction>
</h:form>
</a4j:region>
<a4j:jsFunction name="fetchMenu" action="#{menuBarBean.fetchMenu}">
</a4j:jsFunction>
<javascript>
function displayMenu(){
#{rich:component('HOOFDMENU')}.show();
}
</javascript>
menuBean.java
public String fetchMenu() {
if(currentMenuBar.getChildrenSize() > 1){
return "";
}
showMenuBar = true;
currentMenuBar = getMenuBarComponent(); // The component gets pointed to the full menu
return "TRUE";// "RELOAD" triggers a full page refresh and shows the full menu;
}
public UIComponent getMenuBar() {
if (currentMenuBar == null) {
currentMenuBar = getLazyMenuBarComponent();
}
menuBarComponent = currentMenuBar.build(); // Here the component gets builded. It is chosen to build it in the getter because in the build there is also a check of the users ROLE, which can be changed on the fly.
return menuBarComponent;
}
修改后添加
javascript.js
function showMenu(){ // gets triggered when pressed on the dropdown component
fetchMenu(); // triggers the build-full-menu action
displayMenu(); // sets dropdownbox to show (the menu should show now), I only get the borders of an empty list
}
如果按下菜单激活按钮后按F5,将显示完整菜单。 如果我返回 fetchMenu() return =&#34; RELOAD&#34;页面重新加载,并显示完整的菜单。 如果我尝试重新渲染区域/表格或在HOOFDMENU上我没有得到任何重新渲染的完整菜单。
我怎样才能重新加载页面的菜单部分而不是整页重新加载?
答案 0 :(得分:1)
渲染可能在动作完成之前发生。使用@oncomplete调用另一个执行渲染的jsFunction。即。
<a4j:jsFunction name="fetch" oncomplete="reload()" />
<a4j:jsFunction name="reload" render="…" />
另一方面: fetchmenu函数定义了两次,我不会在任何地方看到它。
你不应该在getter中有任何业务逻辑,为什么不在fetchMenu()方法中调用build()?
我不确定您要对&#34; @region @form .HOOFDMENU&#34;做什么,菜单位于区域内的表单内。 &#34; HOOFDMENU&#34;前面的点。也许不应该在那里。