我跟着this post添加到ListItem中按鈕的點擊功能,但由於某種原因,當表單被提交(點擊按鈕)時,按鈕點擊發生每個項目,而不是個人點擊。我可以通過將onClick添加到項目本身來獲得首選結果,但我寧願將點擊註冊到項目中的按鈕。我如何才能在僅影響項目的按鈕上實現點擊操作?Wicket Listview按鈕onclick要求爲每個項目
ListView<Games> gamesList = new ListView<Games>("gamesList", games) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<Games> item) {
Form<?> form = new Form<>("exportForm");
final SpecialButton exportButton = new SpecialButton("exportButton", item);
form.add(exportButton);
...
item.add(form);
}
}
private class SpecialButton extends AjaxButton {
final ListItem<Games> item;
public SpecialButton(final String id, final ListItem<Games> item) {
super(id);
this.item = item;
}
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
// here you cand do everything you want with the item and the model object of the item.(row)
Games game = item.getModelObject();
System.out.println("Calling file generation with match id: " + game.getGameId()
+ " summoner id: " + game.getSummonerId()
+ " enemy name: " + game.getEnemyChampName());
}
}
Here是一個listview的圖像,如果有幫助。該按鈕用紅色標出。
你可以發佈標記嗎?如果您在標記中的按鈕上設置了一個ID,它將觸發具有相同ID的所有按鈕。在這種情況下,導出按鈕。 – pikand