gpt4 book ai didi

java - Richface 组件的延迟加载

转载 作者:行者123 更新时间:2023-12-01 12:34:50 25 4
gpt4 key购买 nike

我正在尝试“延迟加载”richface 组件。不知何故,如果不刷新页面,我就无法渲染它。我想避免整个页面刷新。

情况:

基本页面加载:

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="RELOAD"页面将重新加载,并且会显示完整菜单。如果我尝试重新渲染区域/表单或在 HOOFDMENU 上,我不会得到任何重新渲染的完整菜单。

如何仅重新加载页面的菜单部分而不重新加载整个页面?

最佳答案

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

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

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

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

我不确定您想对“@region @form .HOOFDMENU”做什么,菜单位于该区域内的表单内。 “HOOFDMENU”前面的点可能也不应该在那里。

关于java - Richface 组件的延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com