在#oninitilize中添加wicket面板

时间:2015-01-21 12:00:30

标签: wicket

嗨,我一直在努力解决这个问题。你可以建议改变。

public class JobDetails extends Panel implements Serializable {
private static Logger LOGGER = Logger.getLogger(JobDetails.class);
public static final long serialVersionUID = 42L;
private List<Job> list;

@Override
protected void onInitialize() {
    super.onInitialize();

}

public JobDetails(String id, final PageParameters params) {
    super(id);
    FeedbackPanel feedbackpanel = new FeedbackPanel("feedbackpanel");
    add(feedbackpanel);
    String JOBNUMBER = params.get("jobnumber").toString();
    String OBJECTTYPE = params.get("objecttype").toString();
    String OBJECTNUMBER = params.get("objectnumber").toString();
    if (JOBNUMBER != null) {
        LOGGER.info("JOBNUMBER != null");
        list = Utils.retrieve(JOBNUMBER);
    } else {
        list = Utils.retrieve(OBJECTTYPE, OBJECTNUMBER);
    }
    DataView dataView = new DataView("jobs", new ListDataProvider(list)) {

        @Override
        public void onConfigure() {
            super.onConfigure();
            setVisible(getDataProvider().size() > 0);
        }

        @Override
        protected void populateItem(final Item item) {
            final Job job = (Job) item.getModelObject();
            Link plink = new Link("parentJobLink") {

                @Override
                public void onClick() {
                    PageParameters p2 = new PageParameters();
                    p2.add("jobNumber", job.getParentJob());
                    JobDetails.this.replaceWith(new ParentJobDetails("innerpanel", p2));
                }
            };
            plink.add(new Label("parentJobLabel", job.getParentJob()));
            item.add(plink);
            item.add(new Label("jobType", job.getJobType()));
            item.add(new Label("whoSubmitted", job.getWhoSubmitted()));
            item.add(new Label("objectType", job.getObjectType()));
            item.add(new Label("objectNumber", job.getObjectNumber()));
            item.add(new Label("objectRevision", job.getObjectRevision()));
            item.add(new Label("jobStatus", job.getJobStatus()));
        }
    };
    dataView.setItemsPerPage(20);
    add(dataView);
    add(new CustomPagingNavigator("navigator", dataView));


    if (list.size() == 0) {

***"Replace the Current Panel with new(SearchInnerPanel("innerpanel", params)"***
    }
}
}

场景:当我搜索作业时,如果作业存在,则此面板中会显示作业,如果该作业不存在,则会将其重定向回搜索面板。我无法重定向回搜索面板。

1 个答案:

答案 0 :(得分:0)

以下是代码的外观:

    public class JobDetails extends Panel {
private static final Logger LOGGER = Logger.getLogger(JobDetails.class);
public static final long serialVersionUID = 42L;
private List<Job> list;

public JobDetails(String id, final PageParameters params) {
    super(id);
    FeedbackPanel feedbackpanel = new FeedbackPanel("feedbackpanel");
    add(feedbackpanel);
}

@Override
protected void onInitialize() {
    super.onInitialize();

    PageParameters params = getPage().getPageParameters();

    String JOBNUMBER = params.get("jobnumber").toString();
    String OBJECTTYPE = params.get("objecttype").toString();
    String OBJECTNUMBER = params.get("objectnumber").toString();
    if (JOBNUMBER != null) {
        LOGGER.info("JOBNUMBER != null");
        list = Utils.retrieve(JOBNUMBER);
    } else {
        list = Utils.retrieve(OBJECTTYPE, OBJECTNUMBER);
    }
    DataView dataView = new DataView("jobs", new ListDataProvider(list)) {

        @Override
        public void onConfigure() {
            super.onConfigure();
            setVisible(getDataProvider().size() > 0);
        }

        @Override
        protected void populateItem(final Item item) {
            final Job job = (Job) item.getModelObject();
            Link plink = new Link("parentJobLink") {

                @Override
                public void onClick() {
                    PageParameters p2 = new PageParameters();
                    p2.add("jobNumber", job.getParentJob());
                    JobDetails.this.replaceWith(new ParentJobDetails("innerpanel", p2));
                }
            };
            plink.add(new Label("parentJobLabel", job.getParentJob()));
            item.add(plink);
            item.add(new Label("jobType", job.getJobType()));
            item.add(new Label("whoSubmitted", job.getWhoSubmitted()));
            item.add(new Label("objectType", job.getObjectType()));
            item.add(new Label("objectNumber", job.getObjectNumber()));
            item.add(new Label("objectRevision", job.getObjectRevision()));
            item.add(new Label("jobStatus", job.getJobStatus()));
        }
    };
    dataView.setItemsPerPage(20);
    add(dataView);
    add(new CustomPagingNavigator("navigator", dataView));


    if (list.size() == 0) {
      replaceWith(new(SearchInnerPanel("innerpanel", params));
    }

}

}

但是,如果将检索list的代码移动到此面板的父级,那会更好。如果列表中有项目,则使用JobDetails面板,否则使用SearchInnerPanel