我有一個面板(見下面的BasePanel),它有一個項目列表和一個「動作」欄,其中放置按鈕。單擊這些按鈕可以通過模型更改列表中的項目。如何使用Wicket正確模擬子面板?
現在我想要相同的面板,但使用稍微不同的按鈕(請參閱下面的CustomPanelA和CustomPanelB)。我有三個面板按鈕的配置。
我該如何建模?我以爲使用wicket:child
,但由於按鈕位於另一個不起作用的檢票組件內。
BasePanel.java
class BasePanel extends Panel {
public BasePanel(String id) {
super(id);
// note: I need this container for refreshing using AJAX
WebMarkupContainer outer = new WebMarkupContainer("outerContainer");
outer.setOutputMarkupId(true);
add(outer);
// ... create listview
outer.add(new ListView("items") { /* implementation of listview */ };
// This container is necessary to show/hide the buttons
WebMarkupContainer actionbar = new WebMarkupContainer("outerContainer");
actionbar.setOutputMarkupId(true);
// ... create default buttons
actionbar.add(new Link("add") { /* implementation of link */);
}
}
BasePanel.html
<html>
<wicket:panel>
<div wicket:id="outerContainer">
<div wicket:id="actionbar" >
<a wicket:id="add">Add</a>
</div>
<div wicket:id="items">
<!-- ... markup for items is here -->
</div>
</div>
</wicket:panel>
</html>
CustomPanelA.java
class CustomPanelA extends BasePanel {
public CustomPanelA (String id) {
super(id);
// add additional buttons only
actionbar.add(new Link("actionA1") { /* implementation of link */);
actionbar.add(new Link("actionA2") { /* implementation of link */);
}
}
CustomPanelA.html
<html>
<wicket:extend>
<a wicket:id="actionA1">ActionA1</a>
<a wicket:id="actionA2">ActionA2</a>
</wicket:extend>
</html>
CustomPanelB.java
class CustomPanelB extends BasePanel {
public CustomPanelB (String id) {
super(id);
// add additional buttons only
actionbar.add(new Link("action_b1") { /* implementation of link */);
actionbar.add(new Link("action_b2") { /* implementation of link */);
}
}
CustomPanelB.html
<html>
<wicket:extend>
<a wicket:id="action_b1">Action b1</a>
<a wicket:id="action_b2">Action b2</a>
</wicket:extend>
</html>
哇,這是很多的信息。感謝您展示不同的方式如何做到這一點。 :-) – Friederike 2014-10-11 17:43:50