我有一個簡單肥胖型形式包括使用一個ListView的形式的元素的數目可變的。每個元素都在一個表格行中,並且包含一個名稱(帶有可以正常工作的鏈接)和一個CheckBox,它將該行標記爲刪除。只有複選框可以在表單中編輯。在表格底部有一個'刪除選定'按鈕,該按鈕將用於刪除具有選定支票的所有條目。檢票 - 形成具有列表項和複選框不設置複選框狀態
我試着用RepeatingView和ListView來做這件事,並且兩者都有同樣的問題 - 當表單被提交時,複選框的內部模型狀態不會更新 - 它們總是假的。在SearchWrapper類的setSelected方法,永遠不會顯示在記錄儀輸出(其它測井是,所以它不是一個記錄問題)
任何人都可以看到爲什麼這是錯的?
public class SavedSearchesTab extends Panel
{
private static final Logger LOGGER = ...
/**
*
*/
public SavedSearchesTab(String p_id)
{
super(p_id);
Form<?> l_form = new Form<Object>("savedsearchform") {
/**
* @see org.apache.wicket.markup.html.form.Form#onSubmit()
*/
protected void onSubmit()
{
LOGGER.info("Form Submitted!");
for(String l_paramName : getRequest().getRequestParameters().getParameterNames()) {
LOGGER.info("FormParam: " + l_paramName + ", value=" + getRequest().getRequestParameters().getParameterValue(l_paramName));
}
onDeleteSelected();
}
};
l_form.setOutputMarkupId(true);
add(l_form);
List<UserSavedSearch> l_searches = getSearches();
ListView<UserSavedSearch> l_repeater = new ListView<UserSavedSearch>("repeater", l_searches) {
protected void populateItem(final ListItem<UserSavedSearch> p_item)
{
final UserSavedSearch l_search = p_item.getModelObject();
SearchWrapper l_wrapper = new SearchWrapper(l_search);
AjaxLink<UserSavedSearch> l_link = new AjaxLink<UserSavedSearch>("searchnamelink") {
private static final long serialVersionUID = 1L;
public void onClick(AjaxRequestTarget p_target)
{
selectSearch(l_search);
}
};
String l_linkText = l_search.getName();
Label l_linkLabel = new Label("searchnamelabel", l_linkText);
l_link.add(l_linkLabel);
p_item.add(l_link);
TextArea<String> l_descriptionArea = new TextArea<String>("searchsummary", new Model<String>(toSummary(l_search)));
p_item.add(l_descriptionArea);
CheckBox l_checkbox = new CheckBox("searchcheckbox", new PropertyModel<Boolean>(l_wrapper, "selected"));
p_item.add(l_checkbox);
}
};
l_repeater.setReuseItems(true);
l_form.add(l_repeater);
}
private List<UserSavedSearch> getSearches() {
List<UserSavedSearch> l_searches = new ArrayList<UserSavedSearch>();
// Make a couple of example ones for testing
UserSavedSearch l_eg = new UserSavedSearch();
l_eg.setName("Example Search 1");
l_eg.setSearchArea(SearchArea.CUSTOMERS);
l_searches.add(l_eg);
l_eg = new UserSavedSearch();
l_eg.setName("Example Search 2");
l_eg.setSearchArea(SearchArea.CUSTOMERS);
l_searches.add(l_eg);
return l_searches;
}
private String toSummary(UserSavedSearch p_search) {
return "Summary of " + p_search.getName(); // TODO
}
protected void onDeleteSelected() {
}
protected void selectSearch(UserSavedSearch p_search) {
LOGGER.info("Search " + p_search.getName() + " should be displayed!");
}
private class SearchWrapper implements Serializable {
private static final long serialVersionUID = 1L;
private UserSavedSearch m_data;
private Boolean m_toDelete;
public SearchWrapper(UserSavedSearch p_data) {
m_data = p_data;
m_toDelete = false;
}
public boolean isSelected() {
return m_toDelete;
}
public void setSelected(boolean p_selected) {
LOGGER.info("SETTING SEARCHWRAPPER SELECTED STATE: " + p_selected);
m_toDelete = p_selected;
}
public UserSavedSearch getSearch() {
return m_data;
}
}
HTML:
<wicket:panel>
<span class="sectiontitle"><wicket:message key="sectiontitle">savedsearches</wicket:message></span>
<form wicket:id="savedsearchform">
<fieldset>
<table id="savedsearchtable">
<tbody wicket:id="repeater">
<tr>
<td><input wicket:id="searchcheckbox" type="checkbox" name="searchselect" wicket:message="value:fragment.select.search" /></td>
<td><a href="#" wicket:id="searchnamelink"><span wicket:id="searchnamelabel">searchname</span></a></td>
</tr>
<tr>
<td colspan="2"><textarea wicket:id="searchsummary" readonly="readonly" rows="3" cols="100"/></td>
</tr>
</tbody>
<tr class="buttonPanel">
<td colspan="2">
<input type="submit" wicket:message="value:button.deleteselectedsearches"/>
</td>
</tr>
</table>
</fieldset>
</form>
</wicket:panel>
在此先感謝。
您是否嘗試過使用'名單'的'ListView'的模式? –