微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想根据表单的内容来更改DataTable的内容(将其视为搜索功能).我以前在wicket 1.5.x中这样做,但是似乎不能让它在小门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); 
} 
}

解决方法

要刷新的组件需要添加到容器中.提交时,需要将容器添加到目标.这样您的组件将被刷新.就像是:
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>

原文地址:https://www.jb51.cc/html/224224.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐