0

我有一个包含 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);
}   

    ...

}

4

2 回答 2

2

使用 ListView.setReuseItems(true) 确保 ListView 中的对象被正确序列化...否则,您每次都会收到不同的对象,并且 .setVisible() 属性将被重置为其默认值(例如 'true' )。

slv.setReuseItems(true);
于 2012-11-21T03:23:24.887 回答
1

尝试

WebMarkupContainer.add(new AttributeModifier("style", new Model("display:none"))); 

或者

WebMarkupContainer.add(new AttributeAppender("style", new Model("display:none"), "="));

反而。

于 2013-04-12T11:13:50.757 回答