代码之家  ›  专栏  ›  技术社区  ›  W vd L

richface组件的延迟加载

  •  0
  • W vd L  · 技术社区  · 10 年前

    我正在尝试“懒加载”一个richface组件。不知怎么的,没有页面刷新,我无法渲染它。我希望避免整页刷新。

    情况:

    基本页面加载了:

    菜单Bean.java

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

    按下“激活菜单”按钮后:

    第.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>
    

    菜单Bean.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=“RELOAD”页面重新加载,同时显示完整菜单。 如果我尝试重新阅读区域/表单或HOOFDMENU,我不会得到任何重新阅读的完整菜单。

    我如何才能只重新加载页面的菜单部分而不重新加载整个页面?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Makhiel    10 年前

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

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

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

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

    我不知道你想用“@region@form.HOUFDMENU”做什么,菜单在区域内的窗体内。“HOOFDMENU”前面的圆点可能也不应该在那里。