【问题标题】:Ajax does not actualize listview in wicketAjax 不在检票口中实现列表视图
【发布时间】:2014-12-19 05:51:13
【问题描述】:

我想创建检票口页面,其中显示包含数据库数据的表格,在此表格下,有一个表格可以在数据库中创建另一个对象。当我保存对象时,页面不会刷新,所以在表中我看不到新行。 如果我理解正确,为了解决这个问题,我必须使用 ajax。我找到了指南(https://cwiki.apache.org/confluence/display/WICKET/How+to+repaint+a+ListView+via+Ajax)并在我的项目中创建了类似的东西,但它不起作用,我找不到它不起作用的原因。我发现其他人遇到了他们试图仅实现行/面板的问题,但这不是我的情况。我什至没有任何例外,只是它什么都不做。你能给我一个建议吗?

.java 文件

public class ListPanel extends Panel {
    private static final long serialVersionUID = 6953172817971228490L;

    @SpringBean
    RezervaceDao rezervaceDao;

    public ListPanel(String id) {
        super(id);

        List<Rezervace> rezervace = rezervaceDao.getAllRezervace();
        ListView listview = new ListView("rezervaceList", rezervace) {
            private static final long serialVersionUID = 3659733406689720345L;

            protected void populateItem(ListItem item) {
                Rezervace r = (Rezervace) item.getModelObject();
                item.add(new Label("casRezervace", r.getCasRezervace()));
                item.add(new Label("jmeno", r.getJmeno()));
                item.add(new Label("adresa", r.getAdresa()));
                item.add(new Label("telefon", r.getTelefon()));
            }
        };
        listview.setReuseItems(true);

        // encapsulate the ListView in a WebMarkupContainer in order for it to
        // update
        WebMarkupContainer listContainer = new WebMarkupContainer("obal");
        // generate a markup-id so the contents can be updated through an AJAX
        // call
        listContainer.setOutputMarkupId(true);
        listContainer
                .add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(3)));
        // add the list view to the container
        listContainer.add(listview);
        // finally add the container to the page
        add(listContainer);

    }
}

.html 文件

<wicket:panel>
    <div wicket:id="obal">
        <table>
            <tr>
                <th>Čas návštěvy</th>
                <th>Jméno a Příjmení</th>
                <th>Adresa</th>
                <th>Kontaktní telefon</th>
            </tr>
            <tr wicket:id="rezervaceList">
                <td><span wicket:id="casRezervace"></span></td>
                <td><span wicket:id="jmeno"></span></td>
                <td><span wicket:id="adresa"></span></td>
                <td><span wicket:id="telefon"></span></td>
            </tr>
        </table>
    </div>
</wicket:panel>

【问题讨论】:

    标签: java ajax listview wicket


    【解决方案1】:

    问题出在:

    List<Rezervace> rezervace = rezervaceDao.getAllRezervace();
    ListView listview = new ListView("rezervaceList", rezervace) 
    

    列表视图使用静态列表初始化自身。相反,它应该在每次刷新时向数据库询问新数据。

    阅读https://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models#WorkingwithWicketmodels-DynamicModels 了解静态与动态模型。

    【讨论】:

    • 是的,这会起作用。小提示:我认为列表是“固定的”(因为“静态”可能会导致与 static 混淆)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多