![](/img/trans.png)
[英]Update one Wicket Panel from clicking an item in another Wicket Panel
[英]Wicket: Submit Form in a Panel from another Panel
我有一個帶有2個面板的頁面(面板a和面板b)。 我使用其中一個面板(面板b)來顯示表格中的一些數據。 我在此表中添加了一個表單和一些復選框。 我的第二個面板(panal a)用於顯示按鈕。 我想通過按下面板a的按鈕來提交面板b的形式,所以我可以用已檢查的東西做一些事情。
我搜索了一下,我想我必須使用ajax提交鏈接。 但我不知道如何得到我的格式行。
頁面標記:
<wicket:extend xmlns:wicket="http://wicket.apache.org">
<div style="margin-top: 60px">
<h2><span wicket:id="header"></span></h2>
<div wicket:id="categoryButtonPanel"></div>
<div wicket:id="categoryTablePanel"></div>
</div>
</wicket:extend>
這是我在面板b( categoryTablePanel
)中添加復選框的方式:
Form form = new Form("form");
final List<Category> selectedCategorys = new ArrayList<Category>(); //my list where my selected rows are in
CheckGroup group = new CheckGroup("group", selectedCategorys);
DataView dv = new DataView("categoryList", dataProvider) {
@Override
protected void populateItem(Item item) {
final Category category = (Category) item.getModelObject();
final CompoundPropertyModel<Category> categoryModel = new CompoundPropertyModel<Category>(category);
item.add(new Check("checkBox", item.getModel()));
// some more binded rows
}
};
標記:
<wicket:panel xmlns:wicket="http://wicket.apache.org">
<form wicket:id="form">
<span wicket:id="group">
<div class="table table-striped table-hover table-condensed" style="overflow: auto !important;" wicket:id="categoryTable">
<table class="table table-striped">
<thead>
<th><input type="checkbox" wicket:id="selector">check/uncheck all</input></th>
</thead>
<tbody>
<tr wicket:id="categoryList">
<td>
<input type="checkbox" wicket:id="checkBox" />
</td>
</tr>
</tbody>
</table>
<div wicket:id="paginator"></div>
</div>
</span>
</form>
</wicket:panel>
其實,我可以檢查每一行,如果我在表單內創建一個普通的按鈕,我可以使用列表selectedCategorys
做一些東西與數據。
現在我想在我的第二個面板( categoryButtonPanel
)中添加一個或兩個按鈕來處理我的數據。 但是怎么樣?
只需使用此構造函數創建AjaxSubmitLink
:
AjaxSubmitLink(String id, Form<?> form)
因此,您需要以某種方式將表單傳遞給其他面板以將其添加到submitlink。 就個人而言,我會將兩個面板添加到一個大的形式。
對於通信,您可以查看wicket事件, IEventSink
和IEvent<T>
。 你可以做這樣的面板1:
public void panel1methodCalledOnSubmit(Category payload) {
send(getPage(), Broadcast.BREADTH, payload);
}
你可以在面板2上回復這個:
@Override
public void onEvent(IEvent<?> event) {
if (event.getPayload() instanceof Category) {
// Do something
}
}
如果你不知道它是如何工作的,那么在做ajax事情時這可能有點棘手。 請查看此頁面以獲取有關事件的更多信息。
RobAu建議的更簡單的設置。 您可以使用FormComponent<T>
對象替換面板以改進表單的泛化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.