wicket 6.0.0-beta2 使用 AjaxButton 提交表单时更新 DataTable 的内容

wicket 6.0.0-beta2 Updating content of DataTable when submitting a form with AjaxButton

提问人:jrochette 提问时间:7/24/2012 最后编辑:BenMoreljrochette 更新时间:9/7/2015 访问量:1272

问:

我想根据表单的内容更改 DataTable 的内容(将其视为搜索栏功能)。我曾经在 wicket 1.5.x 中这样做,但我似乎无法让它在 wicket 6.0.0-beta2 中工作。它似乎没有进入 AjaxButton 的 onSubmit 方法。其他一切都很好,每个组件都正确呈现,并且在页面加载时 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); 
} 
} 
阿贾克斯 1.6 检票口-6

评论

0赞 bert 7/24/2012
您是否测试过是否达到 onSubmit()?通过调试消息还是调试器?
0赞 jrochette 7/26/2012
是的,正如我在问题中所说,它没有达到 onSubmit(),我不知道为什么......
0赞 Joachim Rohde 8/3/2012
难道这张票是有关系的:issues.apache.org/jira/browse/WICKET-4630?(附带说明:您知道有 6.0.0beta-3 可用吗?
0赞 jrochette 8/3/2012
我不认为它与这张票有关,因为它似乎是ajax调用未执行的问题。可能有一些参数我没有为 ajax 调用正确设置(可能在此页面中提到的 updateAjaxAttributes() 中:cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax)。现在我停止使用 wicket 6.x 并回到 1.5.x,一切正常。beta3 值得一试(感谢您提供的信息)
0赞 Rob Audenaerde 2/9/2013
表单如何获取表格?您没有传递它,并且表在上部代码示例中不是最终的

答:

0赞 green 8/19/2015 #1

需要将要刷新的组件添加到容器中。提交时,需要将容器添加到目标。这样,您的组件将被刷新。像这样:

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>