2014-09-05 95 views
0

我试图'延迟加载'一个richface组件。不知何故,我不能得到它没有页面刷新呈现。我想避免整页刷新。延迟加载一个richface组件

现状:

加载

基本页面:

page.xhtml:

menuBean.java

private MenuBarComponent getLazyMenuBarComponent() { 
    if (lazyMenuBar != null) { 
     return lazyMenuBar; 
    } 
    lazyMenuBar = new MainMenuBarLazy(); // no children 
    return lazyMenuBar; 
} 

按下了“激活menu'按钮后

<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菜单激活按钮被按下后, ,全米enu被显示。 如果我返回fetchMenu()返回=“RELOAD”页面重新加载并显示完整菜单。 如果我尝试重新显示区域/表单或HOOFDMENU,我不会收到任何重新提交的完整菜单。

我怎样才能重新加载页面的菜单部分,而不是整页重新加载?

回答

1

这很可能是在动作完成之前发生的。使用@oncomplete调用另一个执行渲染的jsFunction。即

<a4j:jsFunction name="fetch" oncomplete="reload()" /> 
<a4j:jsFunction name="reload" render="…" /> 

在另一方面: 的fetchmenu功能被定义了两次,我没有看到它被调用的任何地方。

你不应该在getter中有任何业务逻辑,为什么不在fetchMenu()方法中调用build()?

我不确定你想要做什么“@region @form .HOOFDMENU”,菜单位于区域内的窗体中。 “HOOFDMENU”前面的点可能不应该在那里。

+0

我没有添加调用js:fetchmenu(js:fetchmenu调用java:fetchmenu)的按钮,因为我认为它不会相关。 我同意关于不是在getter中的逻辑,试图说服我们的'高级'。 amybe我应该这样做;-) 我试着用“@region @form .HOOFDMENU”来表明我试过这些东西(这是一个复制错误)。 - 我试着用你的解决方案取回并重新加载。它不适合我。它仍然显示一个空的菜单列表。在F5之后,完整的菜单通过 – 2014-09-05 09:50:00

+0

显示出来。看起来我已经能够正常工作了。仍然需要找出我做了什么/做错了什么。但是,您提供的方法是有效且正确的(如果实施正确) – 2014-09-05 10:09:35