奇葛格的BLOG

红尘最可笑,我自乐逍遥

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  59 随笔 :: 23 文章 :: 11 评论 :: 0 Trackbacks
These words from Igor tell how to get  "Filterable ListViews":

class MyPage extends WebPage {

private String criteria;
//getter/setter for criteria

public MyPage() {
  IModel listModel=new LoadableDetachableModel() {
          Object load() {
              UserService service=...get user service;
               List users=service.findUsersFiltered(criteria);
              return users;
          }
  }
  add(new ListView("users", listModel) {....});

  // so here we have the listview that will show a list that is filtered on page's criteria property. now we hookup our dropdownchoice in such a way that it modifies this property and when the page refreshes so will the listview because it is using a detachble model.

Form form=new Form();
add(form);

List filters=new ArrayList();
filters.add("a");
filters.add("b");

form.add(new DropDownChoice("filter", new PropertyModel(this, "criteria"), filters) {
wantOnChangeNotifiaction() { return true; });
// here we glue dropdown choice to our criteria property via the property model
}}

and thats it. to overview what we have done:

the listview "pulls" its filter from the criteria property on the page and uses a detachable model so that it refreshes on every request

dropdown choice puts its selection into the criteria property

so the listview is glued to the dropdown choice by sharing a property
posted on 2006-05-06 12:08 奇葛格 阅读(279) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: