我有一个包含 ListView 和子项(表单控件)的 Wicket 面板,但是当我按下内部 CheckBox 时,一些子项的可见性应该会改变。
但是,在 AJAX 更新期间重绘 ListView 后,调用 WebMarkupContainer.setVisible(false) 不会隐藏 ListView 中的项目。
下面的代码:
public class ImagePanel extends Panel {
private ArrayList<ImageEntry> imageEntryList;
public class ImageEntry implements Serializable {
private static final long serialVersionUID = -3987685200930059655L;
public String thumbnail;
public String filename;
public boolean webDownloaded;
public WebMarkupContainer fileUpload;
public WebMarkupContainer webDownload;
}
public ImagePanel(String id) {
this(id, IMAGE_NORMAL);
}
public ImagePanel(String id, int type) {
super(id);
this.type = type;
wmc = new WebMarkupContainer ("wmc");
wmc.setOutputMarkupId(true);
add(wmc);
imageEntryList = new ArrayList<ImageEntry>();
ImageEntry imageEntry = new ImageEntry();
imageEntry.thumbnail = "blah";
imageEntry.filename = "blah";
imageEntryList.add(imageEntry);
ListView<ImageEntry> llv = new LargeImageListView("large_image_list", imageEntryList);
wmc.add(llv);
SmallImageListView slv = new SmallImageListView("small_image_list", imageEntryList);
wmc.add(slv);
}
private final class SmallImageListView extends ListView<ImageEntry> {
private SmallImageListView(String id, List<? extends ImageEntry> list) {
super(id, list);
}
@Override
protected void populateItem(final ListItem<ImageEntry> item) {
...
if (type == IMAGE_WIZARD) {
item.getModelObject().fileUpload = showWizardFileUpload(item);
item.getModelObject().webDownload = showWizardWebDownload(item);
showSortUpDown(item);
showWebCheckbox(item);
}
}
}
private void showWebCheckbox(final ListItem<ImageEntry> item) {
AjaxCheckBox checkbox = new AjaxCheckBox("use_web_image", new PropertyModel<Boolean>(item.getModelObject(), "webDownloaded")) {
public void onUpdate(AjaxRequestTarget target) {
if (getModelObject()) {
System.out.println("Show");
item.getModelObject().fileUpload.setVisible(false);
item.getModelObject().webDownload.setVisible(false);
} else {
System.out.println("Hide");
item.getModelObject().fileUpload.setVisible(false);
item.getModelObject().webDownload.setVisible(false);
}
target.add(wmc);
}
};
item.add(checkbox);
}
...
}