我想根据表单的内容更改DataTable的内容(将其视为搜索栏功能)。我曾经在wicket 1.5.x中这样做,但我似乎无法使其在wicket 6.0.0-beta2中运行。它似乎没有输入AjaxButton的onSubmit方法。其他一切工作正常,每个组件都正确呈现,并且在页面加载时dataTable用正确的数据填充,但是当我单击按钮时,没有任何反应。
非常感谢任何帮助。这是我的代码的样子:
dataTable:
public SubscriberPage(PageParameters parameters) {
super(parameters);
add(new SearchForm("searchForm"));
List<IColumn<Subscriber, String>> columns = new ArrayList<IColumn<Subscriber, String>>();
columns.add(new PropertyColumn<Subscriber, String>(new Model<String>("Telephone Number"),
"tn",
"tn"));
[...]
columns.add(new PropertyColumn<Subscriber, String>(new Model<String>("Initialized MB"),
"initializedMB"));
table = new AjaxFallbackDefaultDataTable<Subscriber, String>("table",
columns,
subscriberDataProvider,
40);
table.setOutputMarkupId(true);
add(table);
}
以下是AjaxButton的表单:
private class SearchForm extends Form<String> {
private static final long serialVersionUID = 1L;
private String tnModel;
private Label tnLabel = new Label("tnLabel", "Telephone Number :");
private TextField<String> tn;
public SearchForm(String id) {
super(id);
tn = new TextField<String>("tnTextField", new PropertyModel<String>(this, "tnModel"));
tn.setOutputMarkupId(true);
add(tnLabel);
add(tn);
AjaxButton lSearchButton = new AjaxButton("searchButton") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
SubscriberFilter filter = new SubscriberFilter();
target.add(table);
if (!(tn.getValue() == null) && !tn.getValue().isEmpty()) {
filter.setTn(tn.getValue());
}
// giving the new filter to the dataProvider
subscriberDataProvider.setFilterState(filter);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
// TODO Implement onError(..)
throw new UnsupportedOperationException("Not yet implemented.");
}
};
lSearchButton.setOutputMarkupId(true);
this.setDefaultButton(lSearchButton);
add(lSearchButton);
}
}
答案 0 :(得分:0)
您要刷新的组件需要添加到容器中。提交时,需要将容器添加到目标。这样您的组件将被刷新。类似的东西:
WebMarkupContainer outputContainer = new WebMarkupContainer("searchResult");
outputContainer.setOutputMarkupId(true);
outputContainer.add(table);
add(outputContainer);
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
//change table ..... stuff ..... ...
//refresh container
target.add(outputContainer);
}
<div wicket:id="searchResult"></div>