gpt4 book ai didi

java - Wicket 口 - ComponentNotFoundException : Component has been removed from page

转载 作者:行者123 更新时间:2023-11-30 10:19:23 24 4
gpt4 key购买 nike

我正在使用 Wicket 7,最近遇到以下异常:

org.apache.wicket.core.request.handler.ComponentNotFoundException:
Component 'navbar:navbarAvatar:navAvatarPanel:4:navAvatarArea:menuPanel:menuItem:menuLink' has been removed from page.

此错误来 self 构建的顶部导航栏。导航栏有一个子菜单 (navAvatarPanel),其中包含额外的菜单链接 (menuLink)。链接被添加到 ArrayList 并使用片段显示在 ListView 中。

这是我的代码:

NavBarPanel.java

public class NavBarPanel extends Panel {
public NavBarPanel(String id) {
super(id);
/* ... */

WebMarkupContainer navBarAvatar = new WebMarkupContainer(NavbarAvatar$wicketId) {
private static final long serialVersionUID = -2447768280463773678L;

@Override
public boolean isVisible() {
return session.isSignedIn();
}
};

List<Panel> avatarMenuItems = new ArrayList<Panel>();
avatarMenuItems.add(new MenuLink(Logout$wicketId, "Logout", WelcomeWebPage.class, menuModel));
/* adding additional links at this point ... */

navBarAvatar.add(new ListView<Panel>("navAvatarPanel", avatarMenuItems) {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<Panel> item) {
final Panel panel = item.getModelObject();
item.add(new MenuFragment(panel, "navAvatarArea"));
}
});

this.add(navBarAvatar);
}
}

public class MenuFragment extends Fragment {
private static final long serialVersionUID = 5735397386662232792L;

public MenuFragment(Panel panel, String area) {
super(area, "menuFragment", NavBarPanel.this);

add(panel);
}
}

NavBarPanel.html

<wicket:panel>
<!-- ... -->
<div wicket:id="navbarAvatar" class="navbar-avatar">
<ul>
<wicket:container wicket:id="navAvatarPanel">
<wicket:container wicket:id="navAvatarArea"/>
</wicket:container>
</ul>
</div>
<!-- ... -->
<wicket:fragment wicket:id="menuFragment">
<wicket:container wicket:id="menuPanel"></wicket:container>
</wicket:fragment>
</wicket:panel>

菜单链接.java

public MenuLink(String markupId, String label, Class<? extends Page> page, MenuModel model) {
super("menuPanel");
this.markupId = markupId;
this.page = page;
this.model = model;
this.initComponentTree(label);
}

private void initComponentTree(final String label) {
WebMarkupContainer menuItem = new WebMarkupContainer("menuItem");

Link<Void> menuLink = new Link<Void>("menuLink") {
private static final long serialVersionUID = 1L;

@Override
public void onClick() {
MenuLink.this.menuOnClick(label);
}
};

menuLink.add(new Label("menuLabel", label));
menuLink.setMarkupId(this.markupId);

menuItem.add(menuLink);

this.add(menuItem);
}

MenuLink.html

<wicket:panel>
<li wicket:id="menuItem">
<a wicket:id="menuLink">
<span wicket:id="menuLabel">[label]</span>
</a>
</li>
</wicket:panel>

我不知道这个错误是从哪里来的。我也没有成功找到有关此异常的更多信息。

最佳答案

我的猜测是 http session 已过期并且找不到菜单项,因为 isVisible = session.isSignedIn(); 导致整个菜单不存在。

如果是这种情况,则应改进 Wicket 以提供更好的异常消息,告知确切找不到哪个组件,而不是请求的组件路径。

附言建议使用 onConfigure() {setVisible(...)} 而不是重写 isVisible(),因为后者在渲染期间被调用多次并且可能会更慢。

关于java - Wicket 口 - ComponentNotFoundException : Component has been removed from page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48661372/

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