wicket 中ListView和WebMarkupContainer以及AjaxButton的使用

wsd 2012-09-27

此例子为wicket中在页面中点检索后,在本页面显示出检索结果所用到的控件:

importjava.util.ArrayList;

importjava.util.List;

importjp.co.infomart.foods.common.admin.page.BasePage;

importorg.apache.wicket.ajax.AjaxRequestTarget;

importorg.apache.wicket.ajax.markup.html.form.AjaxButton;

importorg.apache.wicket.markup.html.WebMarkupContainer;

importorg.apache.wicket.markup.html.basic.Label;

importorg.apache.wicket.markup.html.form.Form;

importorg.apache.wicket.markup.html.list.ListItem;

importorg.apache.wicket.markup.html.list.ListView;

/**

*

*@authoradmin

*/

publicclassTest_ListViewextendsBasePage{

privateFormform;

privatestaticListbooks=newArrayList();

WebMarkupContainercontainer;

publicTest_ListView(){

super();

form=newForm("myForm");

this.add(form);

container=newWebMarkupContainer("listViewContainer");

container.setOutputMarkupId(true);

//

ListViewlistView=newListView("books",books){

@Override

protectedvoidpopulateItem(ListItemitem){

Test_ListViewModelbook=(Test_ListViewModel)item.getModelObject();

item.add(newLabel("id",Integer.toString(book.getId())));

item.add(newLabel("title",book.getTitle()));

item.add(newLabel("author",book.getAuthor()));

}

};

container.add(listView);

form.add(container);

AjaxButtonajaxButton=newAjaxButton("ajaxButton"){

@Override

protectedvoidonSubmit(AjaxRequestTargetart,Form<?>form){

init();

art.addComponent(container);

}

@Override

protectedvoidonError(AjaxRequestTargetart,Form<?>form){

thrownewUnsupportedOperationException("Notsupportedyet.");

}

};

form.add(ajaxButton);

}

publicvoidinit(){

books.clear();

for(inti=1;i<10;i++){

Test_ListViewModelbook=newTest_ListViewModel();

book.setId(i);

book.setAuthor("author"+i);

book.setTitle("title"+i);

books.add(book);

}

}

}

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">

<title>test</title>

</head>

<bodybgcolor="#FFFFFF"text="#000000"topmargin="0"leftmargin="0"marginwidth="0"marginheight="0"onUnload="fCloseWin()">

<formwicket:id="myForm">

<divwicket:id="listViewContainer">

<tablewidth="240"border="1">

<tr>

<th>序号</th>

<th>书名</th>

<th>作者</th>

</tr>

<trwicket:id="books">

<tdwicket:id="id">id</td>

<tdwicket:id="title">title</td>

<tdwicket:id="author">author</td>

</tr>

</table>

</div>

<inputtype="submit"wicket:id="ajaxButton"/>

</form>

</body>

</html>

publicclassTest_ListViewModel{

privateintid;

privateStringtitle;

privateStringauthor;

publicStringgetAuthor(){

returnauthor;

}

publicvoidsetAuthor(Stringauthor){

this.author=author;

}

publicintgetId(){

returnid;

}

publicvoidsetId(intid){

this.id=id;

}

publicStringgetTitle(){

returntitle;

}

publicvoidsetTitle(Stringtitle){

this.title=title;

}

}

相关推荐

开发中的点点滴滴 / 0评论 2018-03-30