0

大家好,我的检票口项目似乎有问题。

本质上,我有一个 AjaxLink,单击它时应该更新可加载可拆卸模型并使用更新模型的结果重新呈现列表视图

这是我的代码

package com.blackwell.wicket.manager;



public class ManageExercise extends BaseManagerPage {
private static final long serialVersionUID = -3241765837700606142L;

private ModalWindow mwAddExercise;

private Integer searchId;
private String name;
private String complexity;
private LoadableDetachableModel<List<Exercise>> modelList;

@SpringBean
ExerciseJdbc exerciseJdbc;

public ManageExercise() {

    add(mwAddExercise = new ModalWindow("mwAddExercise"));

    final WebMarkupContainer wmc = new WebMarkupContainer("wmc");
    wmc.setOutputMarkupId(true);

    modelList = exerciseModel(searchId, name, complexity);

    Form<String> searchForm = new Form<String>("searchForm");
    searchForm.add(new TextField<Integer>("searchId",
            new PropertyModel<Integer>(this, "searchId")));
    searchForm.add(new TextField<String>("searchName",
            new PropertyModel<String>(this, "name")));
    // searchForm.add(new DropDownChoice<String>("searchComplexity",
    // new PropertyModel<String>(this, "complexity")));
    searchForm.add(new AjaxLink<String>("searchSubmit") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            modelList = exerciseModel(searchId, name, complexity);
            target.add(wmc);
        }

    });

    add(searchForm);

    ListView<Exercise> lvExercise = new ListView<Exercise>("lvExercise",
            modelList) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Exercise> item) {
            final Exercise model = item.getModelObject();
            item.add(new Label("id", Integer.toString(model.getId())));
            item.add(new Label("name", model.getName()));
            item.add(new ExternalLink("demoUrl", model.getDemoUrl(), model
                    .getDemoUrl()));
            item.add(new Label("complexity", model.getComplexity()
                    .getLevel()));
            item.add(new AjaxLink<String>("edit") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    renderAddExercise(item.getModelObject());
                    mwAddExercise.show(target);
                }
            });
            item.add(new AjaxLink<String>("delete") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    exerciseJdbc.disableExercise(model);
                    target.add(wmc);

                }
            });
        }
    };

    wmc.add(lvExercise);
    add(wmc);

    mwAddExercise.setWindowClosedCallback(new WindowClosedCallback() {
        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target) {
            target.add(wmc);
        }
    });

    AjaxLink<String> addExercise = new AjaxLink<String>("addExercise") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            renderAddExercise(new Exercise());
            mwAddExercise.show(target);

        }

    };

    add(addExercise);

}

private LoadableDetachableModel<List<Exercise>> exerciseModel(
        final Integer id, final String name, final String complexity) {
    LoadableDetachableModel<List<Exercise>> exercideModel = new LoadableDetachableModel<List<Exercise>>() {
        private static final long serialVersionUID = 1L;

        protected List<Exercise> load() {
            return exerciseJdbc.fetchAllExercises(id, name, null,
                    complexity);
        }
    };
    return exercideModel;
}

private void renderAddExercise(Exercise exercise) {
    mwAddExercise.setContent(new AddExercisePanel(mwAddExercise
            .getContentId(), exercise, mwAddExercise));
}

public Integer getSearchId() {
    return searchId;
}

public void setSearchId(Integer id) {
    this.searchId = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getComplexity() {
    return complexity;
}

public void setComplexity(String complexity) {
    this.complexity = complexity;
}

}

现在的问题是点击链接时这没有发生。

我已经验证了在 load() 方法中运行的方法返回了我在传递正确参数时所期望的结果。

任何帮助,将不胜感激

谢谢

4

2 回答 2

2

当你这样做时:

modelList = exerciseModel(searchId, name, complexity);

您正在创建 的新实例LoadableDetachableModel,因此您ListView仍然拥有前一个实例。

在 Wicket 中,您必须更新模型的对象,而不是模型本身。

于 2013-03-31T00:40:44.157 回答
0

在 populateItem 中也使用属性模型

新标签(“复杂性”,新 PropertyModel(item.getModel(),“复杂性.level”))

也分离模型列表(onDetach())

于 2013-04-01T20:51:44.237 回答