2014-09-05 114 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