我正在使用 Wicket 7,最近遇到以下异常:
org.apache.wicket.core.request.handler.ComponentNotFoundException:
Component 'navbar:navbarAvatar:navAvatarPanel:4:navAvatarArea:menuPanel:menuItem:menuLink' has been removed from page.
这个错误来自我构建的顶部导航栏。导航栏有一个包含附加菜单链接 (menuLink) 的子菜单 (navAvatarPanel)。链接被添加到 ArrayList 并使用片段显示在 ListView 中。
这是我的代码:
导航栏面板.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);
}
}
导航栏面板.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>
MenuLink.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);
}
菜单链接.html
<wicket:panel>
<li wicket:id="menuItem">
<a wicket:id="menuLink">
<span wicket:id="menuLabel">[label]</span>
</a>
</li>
</wicket:panel>
我不知道这个错误来自哪里。我也没有成功找到有关此异常的更多信息。