我正在尝试将一个片段嵌套到另一个片段中。列表视图充满了父片段(有效),现在我希望在某些情况下第二个片段嵌套在第一个片段中。这是我填充列表视图的代码:
@Override
protected void populateItem(final Item<Message> item) {
Message msg = item.getModelObject();
MessageFragment msgFragment = new MessageFragment("entry", "messageFragment", this, msg);
WebMarkupContainer msgRatingContainer = new WebMarkupContainer("messageRatingContainer");
msgRatingContainer.setVisible(false);
if(msg.getType() == MessageType.RESERVATION){
msgRatingContainer.add(new MessageRatingFragment("messageRatingContainer", "messageRatingFragment",this, msg));
msgRatingContainer.setVisible(true);
}
msgFragment.add(msgRatingContainer);
item.add(msgFragment);
}
涉及的标记:
<li wicket:id="listView"><div wicket:id="entry"></div></li>
<wicket:fragment wicket:id="messageFragment">
<div class="MessageAlert">
My Parent fragment content
</div>
<div wicket:id="messageRatingContainer"></div>
<wicket:fragment wicket:id="messageRatingFragment">
My nested fragment content
</wicket:fragment>
</wicket:fragment>
如果我没有任何嵌套片段(if 条件为假),则 UI 按预期呈现,如果条件为真,我会收到以下错误:
org.apache.wicket.WicketRuntimeException: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered).
1. [MarkupContainer [Component id = messageRatingContainer]]
2. [MarkupContainer [Component id = messageRatingContainer]]
我想这与组件层次结构有关,但我不知道哪种方式是正确的。