wicket - PageableListView不起作用

时间:2013-03-09 09:09:17

标签: java wicket wicket-1.5

我正在研究wicket,我应该在点击导航栏后渲染视图没有任何反应 请帮帮我。

<div class="colums data" wicket:id="BooksListViewContainer">

    <div wicket:id="booksListView">
        <div class="col-left data" wicket:id="bookName"></div>
        <div class="col-middle data" wicket:id="author"></div>
        <div class="col-middle data" wicket:id="genre"></div>
        <div class="col-middle data" wicket:id="language"></div>
        <div class="col-middle data" wicket:id="datePublished"></div>
    </div>
    <div wicket:id="navigator" class="navi">xxx</div>
</div>

和java:

 public class HomePage extends WebPage {

    transient LibaryServices libaryService ;
    Component sortBtns [] ;

public HomePage(final PageParameters parameters) {
    super(parameters);
    initPage();
}

private void initPage() {
    libaryService = new LibaryServices();
    add(getBooksListViewContainer());
}

private WebMarkupContainer getBooksListViewContainer(){
    String id = "BooksListViewContainer" ;
    WebMarkupContainer c = (WebMarkupContainer) get(id);
    if (c != null)
        return c;

    final WebMarkupContainer container = new WebMarkupContainer(id);
    container.add(getBooksListView());
    container.add(getNavigator());
    container.setOutputMarkupId(true);
    return container;
}

@SuppressWarnings("unchecked")
private PageableListView<Book> getBooksListView() {
    String id = "booksListView";
    PageableListView<Book> c = (PageableListView<Book>)get(id);
    if (c != null)
        return c;
    final PageableListView<Book> booksListView = new PageableListView<Book>(id, libaryService.getBooks(), 4) {
        @Override
        protected void populateItem(ListItem<Book> listBookItem) {
            Book book = (Book) listBookItem.getModelObject();

            listBookItem.add(new Label("author", book.getAuthor()));
            listBookItem.add(new Label("bookName", book.getBookName()));
            listBookItem.add(new Label("language", book.getBookLanguage()));
            listBookItem.add(new Label("genre", book.getGenre()));
            listBookItem.add(new Label("datePublished", book.getDatePublished()));

            listBookItem.setVisible(listBookItem.isVisible()&&
                        book.isShouldBeDisplayedAfterPassFilter());     
        }
        @Override
        protected IModel<Book> getListItemModel(
                IModel<? extends List<Book>> listViewModel, int index) {
            return super.getListItemModel(listViewModel, index);
        }
    };
    booksListView.setOutputMarkupId(true);
    booksListView.setMarkupId(id);
    return booksListView;
}
    public SortingDataUtil getSortingDataUtil(){
    return SortingDataUtil.getInstace();
}

private AjaxPagingNavigator getNavigator() {
String id = "navigator";
AjaxPagingNavigator navigator = (AjaxPagingNavigator) get(id);
if (navigator == null) {
    navigator = new AjaxPagingNavigator(id, getBooksListView()) {
    @Override
    protected void onAjaxEvent(AjaxRequestTarget target) {
        super.onAjaxEvent(target);
    }
    };
    navigator.setOutputMarkupId(true);
}
return navigator;
}       

}

这是我得到的例外

意外的RuntimeException

  Last cause: Argument 'component' may not be null.
 WicketMessage: Method onRequest of interface      org.apache.wicket.behavior.IBehaviorListener targeted at      org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigationLink$1@321af6fe on component [AjaxPagingNavigationLink [Component id = pageLink]] threw an exception

堆栈跟踪

根本原因:

 java.lang.IllegalArgumentException: Argument 'component' may not be null.
 at org.apache.wicket.util.lang.Args.notNull(Args.java:41)
 at org.apache.wicket.ajax.AjaxRequestHandler.add(AjaxRequestHandler.java:226)
 at org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator.onAjaxEvent(AjaxPagingNavigator.java:152)
 at com.wicketlibary.HomePage$3.onAjaxEvent(HomePage.java:146)
 at org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigationBehavior.onEvent(AjaxPagingNavigationBehavior.java:82)
 at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:131)
 at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:603)

编辑:我的版本是

  <wicket.version>6.6.0</wicket.version>

1 个答案:

答案 0 :(得分:0)

如果你认为它是一个错误,你应该创建一个快速入门并提交。

在你这样做之前,我会改变你获取对PageableListView的引用的方式,而是创建一个类变量,设置它并在创建AjaxPagingNavigator时使用它。您是否使用debug来确保从AjaxPagingNavigator调用时“c”不为null。我使用与你一样的wicket版本在我的环境中工作。我的代码唯一的区别是我通过调用get(id)

来获取我的变量