关于该项目的一些信息:基本上一直在尝试使搜索功能起作用以更新我以前做过的列表视图并且没有问题;到现在。我似乎找不到问题,希望你们能找到!
运行时出现空指针问题:
modelList.setObject(exerciseJdbc.fetchExercisesByAttr(3,
exercise.getName(), null, exercise.getComplexity()
.getLevel()));
现在我确信这是一个简单的错误,但我终其一生都无法弄清楚。
public class ManageExercise extends BaseManagerPage {
private static final long serialVersionUID = -3241765837700606142L;
private ModalWindow mwAddExercise;
private LoadableDetachableModel<List<Exercise>> modelList;
@SpringBean
ExerciseJdbc exerciseJdbc;
public ManageExercise() {
final Exercise exercise = new Exercise();
add(mwAddExercise = new ModalWindow("mwAddExercise"));
final WebMarkupContainer wmc = new WebMarkupContainer("wmc");
wmc.setOutputMarkupId(true);
try{
modelList = exerciseModel();
}
catch(Exception e){
e.printStackTrace();
}
Form<Exercise> searchForm = new Form<Exercise>("searchForm", new CompoundPropertyModel<Exercise>(exercise));
searchForm.add(new TextField<Integer>("searchId", new PropertyModel<Integer>(exercise, "id")));
searchForm.add(new TextField<String>("searchName", new PropertyModel<String>(exercise, "name")));
// searchForm.add(new DropDownChoice<String>("complexity.level",
// new PropertyModel<String>(this, "complexity")));
searchForm.add(new AjaxLink<String>("searchSubmit") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
modelList.setObject(exerciseJdbc.fetchExercisesByAttr(exercise.getId(), exercise.getName(), null, exercise.getComplexity().getLevel()));
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() {
LoadableDetachableModel<List<Exercise>> exercideModel = new LoadableDetachableModel<List<Exercise>>() {
private static final long serialVersionUID = 1L;
protected List<Exercise> load() {
return exerciseJdbc.fetchAllExercises();
}
};
return exercideModel;
}
private void renderAddExercise(Exercise exercise) {
mwAddExercise.setContent(new AddExercisePanel(mwAddExercise
.getContentId(), exercise, mwAddExercise));
}
}
如果我错过了任何所需的信息,请告诉我,但我有一种可怕的感觉,这是一种非常愚蠢的错误。