我試圖'延遲加載'一個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,我不會收到任何重新提交的完整菜單。
我怎樣才能重新加載頁面的菜單部分,而不是整頁重新加載?
我沒有添加調用js:fetchmenu(js:fetchmenu調用java:fetchmenu)的按鈕,因爲我認爲它不會相關。 我同意關於不是在getter中的邏輯,試圖說服我們的'高級'。 amybe我應該這樣做;-) 我試着用「@region @form .HOOFDMENU」來表明我試過這些東西(這是一個複製錯誤)。 - 我試着用你的解決方案取回並重新加載。它不適合我。它仍然顯示一個空的菜單列表。在F5之後,完整的菜單通過 – 2014-09-05 09:50:00
顯示出來。看起來我已經能夠正常工作了。仍然需要找出我做了什麼/做錯了什麼。但是,您提供的方法是有效且正確的(如果實施正確) – 2014-09-05 10:09:35