wicket 中ListView和WebMarkupContainer以及AjaxButton的使用

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





import java.util.ArrayList;
import java.util.List;
import jp.co.infomart.foods.common.admin.page.BasePage;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

/**
*
* @author admin
*/
public class Test_ListView  extends BasePage {
        private Form form;
        private static List books = new ArrayList();
        WebMarkupContainer container;
       
        public Test_ListView(){
            super();
        form = new Form("myForm");
        this.add(form);
        container = new WebMarkupContainer("listViewContainer");
        container.setOutputMarkupId(true);
//       
        ListView listView = new ListView("books",books){

            @Override
            protected void populateItem(ListItem item) {
                Test_ListViewModel book = (Test_ListViewModel)item.getModelObject();
                item.add(new Label("id",Integer.toString(book.getId())));
                item.add(new Label("title",book.getTitle()));
                item.add(new Label("author",book.getAuthor()));
            }
       
        };
        container.add(listView);
        form.add(container);

        AjaxButton ajaxButton = new AjaxButton("ajaxButton") {

            @Override
            protected void onSubmit(AjaxRequestTarget art, Form form) {
                init();
                art.addComponent(container);
            }

            @Override
            protected void onError(AjaxRequestTarget art, Form form) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
       
        };
         form.add(ajaxButton);
        }
       
        public void init(){
            books.clear();
         for(int i=1;i<10;i++){
              Test_ListViewModel book = new Test_ListViewModel();
              book.setId(i);
              book.setAuthor("author"+i);
              book.setTitle("title"+i);
              books.add(book);
           }
       
        }
}








test


   

       

       
           
               
               
               
           
           
           
               
               
               
           
           
       
序号 书名 作者
id title author

        

       
   








public class Test_ListViewModel {
    private int id;
    private String title;
    private String author;

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
   
   
}

你可能感兴趣的:(wicket,Ajax,ListView,AjaxButton)