2

尝试添加具有指定排序属性的列时,我得到了 NPE。关于我做错了什么的任何想法?

这是课程:

@Entity
@Table(name="checklist_template")
public class CheckListTemplate extends DomainObject implements Comparable<CheckListTemplate>, Serializable {

    private static final long serialVersionUID = 2959377496669050427L;

    @Id
    @GeneratedValue
    private Long id;

    @Column(nullable=false)
    private String name;

    public CheckListTemplate() {}

    public CheckListTemplate(String name) {
        this.name = name;
    }

    //some other attributes, getters, setters etc

}

这是代码:

public class CheckListTemplateDataPanel extends Panel {

    @SpringBean
    public ChecklistTemplateService checklistTemplateService;

    DataTable<CheckListTemplate> table;
    NavigationToolbar navigationToolbar;
    ChecklistTemplateProvider checklistTemplateProvider;

    public CheckListTemplateDataPanel(String id) {
        super(id);

        IColumn[] columns = new IColumn[1];

        columns[0] = new PropertyColumn<CheckListTemplate>(Model.of("Name"), "name", "name"); //this is what generates the exception. if i ignore the third argument, the code works but i get no link to click for sorting

        table = new DataTable<CheckListTemplate>("datatable", columns, checklistTemplateProvider =  new ChecklistTemplateProvider(), 10);
        table.setOutputMarkupId(true);
        table.addBottomToolbar(navigationToolbar = new NavigationToolbar(table));
        table.addTopToolbar(new HeadersToolbar(table, null));
        add(table);

    }

    private class ChecklistTemplateProvider extends SortableDataProvider<CheckListTemplate> {

        public ChecklistTemplateProvider() {
            setSort("name", true);
        }

        @Override
        public Iterator<? extends CheckListTemplate> iterator(int first, int count) {
            return checklistTemplateService.findAll(new PageRequest(table.getCurrentPage(), count)).iterator();

        }

        @Override
        public int size() {
            return safeLongToInt(checklistTemplateService.count());
        }

        @Override
        public IModel<CheckListTemplate> model(CheckListTemplate object) {
            return Model.of(object);
        }

        public void setFilterString(String filterString){
            this.filterString = filterString;
        }
    }

    public static int safeLongToInt(long l) {
        if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
            throw new IllegalArgumentException
                    (l + " cannot be cast to int without changing its value.");
        }
        return (int) l;
    }
}

这是一个例外:

2012 May 03 13:58:58,480[ERROR] - RequestCycle - Exception in rendering component: [MarkupContainer [Component id = header]]
org.apache.wicket.WicketRuntimeException: Exception in rendering component: [MarkupContainer [Component id = header]]
    at org.apache.wicket.Component.renderComponent(Component.java:2729)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1441)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.markup.repeater.AbstractRepeater.renderChild(AbstractRepeater.java:122)
    at org.apache.wicket.markup.repeater.AbstractRepeater.onRender(AbstractRepeater.java:103)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1441)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:697)
    at org.apache.wicket.markup.html.panel.Panel.onComponentTagBody(Panel.java:114)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable$ToolbarContainer.onRender(DataTable.java:429)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.markup.repeater.AbstractRepeater.renderChild(AbstractRepeater.java:122)
    at org.apache.wicket.markup.repeater.AbstractRepeater.onRender(AbstractRepeater.java:103)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1441)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:697)
    at org.apache.wicket.markup.html.panel.Panel.onComponentTagBody(Panel.java:114)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1441)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:697)
    at org.apache.wicket.markup.html.panel.Panel.onComponentTagBody(Panel.java:114)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1441)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:66)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:73)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:66)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:73)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:66)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1604)
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1528)
    at org.apache.wicket.Component.renderComponent(Component.java:2690)
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.MarkupContainer.autoAdd(MarkupContainer.java:229)
    at org.apache.wicket.markup.resolver.MarkupInheritanceResolver.resolve(MarkupInheritanceResolver.java:73)
    at org.apache.wicket.markup.resolver.ComponentResolvers.resolve(ComponentResolvers.java:81)
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1445)
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1555)
    at org.apache.wicket.Page.onRender(Page.java:1594)
    at org.apache.wicket.Component.render(Component.java:2521)
    at org.apache.wicket.Page.renderPage(Page.java:932)
    at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.respond(BookmarkablePageRequestTarget.java:261)
    at org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:105)
    at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1258)
    at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
    at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
    at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
    at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
    at org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByLink$CssModifier.onComponentTag(OrderByLink.java:208)
    at org.apache.wicket.Component.renderComponentTag(Component.java:4270)
    at org.apache.wicket.Component.renderComponent(Component.java:2681)
    ... 125 more
4

2 回答 2

3

错误在这里:

table.addTopToolbar(new HeadersToolbar(table, null));

您必须提供 DataProvider 的实例,而不是null在构造函数中。

于 2012-05-03T08:33:41.447 回答
2

好的,我明白了,感谢随附的 myproject.zip 代码。

table.addTopToolbar(new HeadersToolbar(table, null));

是导致问题的行,您必须将 ISortStateLocator 传递给HeadersToolbar该类。

于 2012-05-03T08:34:04.157 回答