java - WICKET - 使用 ajaxButton 刷新数据 View

标签 java refresh wicket

由于 ajaxButton 中的 onSubmit 函数,我正在尝试刷新 DataView。 我创建了一个包含两个 DropDownChoice 和一个 AjaxButton 的表单。

当我在 onSubmit 函数中单击 ajaxButton 时,我会调用 DAO 函数,并且我想用 DAO 中的新列表替换之前为空的 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);
    }
};

关于java - WICKET - 使用 ajaxButton 刷新数据 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24506426/

相关文章:

java - Hecl 脚本是否与 native J2ME midlet 一样强大?

java - 未知错误 :java. lang.nullPointerException

java - 电子邮件 Intent 崩溃

java - list 更改后 Android 上出现 NoClassDefFOoundError

javascript - Google DFP slotRenderEnded 函数在 pubads().refresh([currentSlot]) 后工作错误

javascript - 在浏览器调整大小时刷新选定的 iframe

http - 如何在 Wicket 中限制上传文件的大小

selenium - 等待特定条件时通过WebDriver刷新网页

java - Wicket - 进度/多个标签更新

java - 如何将 CAS 身份验证与 Apache wicket 应用程序集成?