繁体   English   中英

WICKET-使用ajaxButton刷新DataView

[英]WICKET - DataView refresh with ajaxButton

由于ajaxButton中的onSubmit函数,我试图刷新DataView。 我用两个DropDownChoice和一个AjaxButton创建一个表单。

当我在onSubmit函数中单击ajaxButton时,我将调用DAO函数,并希望用DAO的新列表替换以前为null的ListDataProvider。

final private WebMarkupContainer wmc = new WebMarkupContainer("wmc");
private ListDataProvider<ComparePhoto> dataP = new ListDataProvider<ComparePhoto>();

dataView = (DataView<ComparePhoto>)new DataView<ComparePhoto>("vcomponents", dataP){

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<ComparePhoto> item) {

                ComparePhoto c = item.getModelObject();

                System.out.println("idCarto : "+c.getIdCarto());

                RepeatingView repeatingView = new RepeatingView("dataRow");
                repeatingView.add(new Label(repeatingView.newChildId(), c.getIdCarto()));
                [...]

                item.add(repeatingView);
        }
    };

    dataView.setOutputMarkupId(true);
    wmc.setOutputMarkupId(true);
    wmc.add(dataView);
    add(wmc);

            AjaxButton b = new AjaxButton("btnSubmit") {

               protected void onSubmit(AjaxRequestTarget target, Form<?> form)
               {
                   dataP = new ListDataProvider<ComparePhoto>(lstComparePhoto);

                target.add(wmc);
               }
            }

form.add(b);
add(form);

我的HTML代码:

<form wicket:id="formComparePicture">
                <div align="center"><label for="dateChoiceOne"><select wicket:id="dateOne"></select></label></div><br/>
                <div align="center"><label for="dateChoiceTwo"><select wicket:id="dateTwo"></select></label></div><br/>

                <button wicket:id="btnSubmit">compare</button>
                <br/><br/><br/>
            </form>

            <div wicket:id="wmc">
                <div wicket:id="feedback"></div>
                <table id="componentTable">
                    <thead>
                        <tr>
                            <th>id</th>

                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>id</th>
                        </tr>
                    </tfoot>

                    <tbody>

                        <tr wicket:id="vcomponents">
                            <td wicket:id="dataRow"></td>
                        </tr>

                    </tbody>
                </table>
            </div>

绝对没有发生...

谢谢你的帮助

您必须重写ListDataProvider#getData()才能始终提供最新列表:

private List<ComparePhoto> photos = new List<ComparePhoto>();

...

ListDataProvider<ComparePhoto> dataP = new ListDataProvider<ComparePhoto>() {
    protected List<T> getData() {
        return photos;
    }
};

dataView = new DataView<ComparePhoto>("vcomponents", dataP) {
    ...
};

AjaxButton b = new AjaxButton("btnSubmit") {
    protected void onSubmit(AjaxRequestTarget target, Form<?> form)
    {
        photos = ...;

        target.add(wmc);
    }
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM