2012-07-23 38 views
10

我想根據表單的內容(將其視爲搜索欄功能)更改DataTable的內容。我曾經在wicket 1.5.x中這樣做過,但我似乎無法使它在6.0.0-beta2版本中工作。它似乎沒有進入AjaxButton的onSubmit方法。其他一切正常,每個組件都可以正確呈現,並且在頁面加載時dataTable中填充了正確的數據,但是當我單擊按鈕時,什麼都不會發生。wicket 6.0.0-beta2使用AjaxButton提交表單時更新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

你測試,如果你到達的onsubmit()?通過調試消息或調試器? – bert 2012-07-23 20:07:17

+0

是的,正如我在我的問題中所說,它沒有達到onSubmit(),我不知道爲什麼...... – jrochette 2012-07-25 18:43:37

+0

難道這個票是相關的:https://issues.apache.org/jira/browse/WICKET-4630? (附註:您知道有6.0.0beta-3可用?) – 2012-08-02 16:47:08

回答

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>