wicket dataview中的错误,需要帮助来修复它

时间:2014-05-27 06:10:36

标签: java wicket

我试图执行wicket程序来完成以下任务, 一个。表单中有一个提交按钮 湾当我点击我必须在同一页面的数据视图中显示输出 我的代码如下,需要您帮助修复错误并获取输出

Demoapplication.java

package com.demo.application;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.demo.pages.*;

public class DemoApplication extends WebApplication {

    @Override
    public Class<? extends Page> getHomePage() {
        return DemoHomePage.class;
    }

}

DemoHomePage.html:

<html>
<body>
    <form wicket:id="homePageForm">
        <input type="submit" value="ok">
    </form>
    <table>
        <tr>
            <th> Id </th>
            <th> Name </th>
        </tr>
        <tr wicket:id="row">
            <td wicket:id="dataRow"> </td>
        </tr>
    </table>
</body>
</html>

DemoHomePage.java

package com.demo.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.markup.html.list.*;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import com.sun.xml.internal.ws.org.objectweb.asm.Label;

public class DemoHomePage extends WebPage {

    public DemoHomePage () {
        Form form=new Form("homePageForm") {

            public void submit(){

                List<DemoBean> list = new ArrayList();
                list.add(new DemoBean("1","ram"));
                list.add(new DemoBean("2","sam"));

                ListDataProvider<DemoBean> listDataProvider = new ListDataProvider<DemoBean>(list);

                DataView<DemoBean> dataView = new DataView<DemoBean>("row",listDataProvider) {

                    protected void populateItem(Item<DemoBean> item) {

                        DemoBean bean=item.getModelObject();
                        RepeatingView repeatingView = new RepeatingView("dataRow");
                        repeatingView.add(new Label(repeatingView.newChildId().bean.getId()));
                        repeatingView.add(new Label(repeatingView.newChildId().bean.getName()));
                        item.add(repeatingView);
                    }
                };

                add(dataView);
            }
        };
    }

}

DemoBean.java

package com.demo.pages;

public class DemoBean {
    public String id;
    public String name;

    public DemoBean(String id,String name) {
        this.id=id;this.name=name;
    }

    public String getId(){
        return this.id;
    }

    public void setId(String id){
        this.id=id;
    }

    public String getName(){
        return this.name;
    }

    public void setName(String name){
        this.name=name;
    }
}

我收到以下错误。

  

错误:绑定不匹配:DemoBean类型不是有效替代   对于类型的有界参数   ListDataProvider方法add(Component ...)在类型中   MarkupContainer不适用于参数(Label)

1 个答案:

答案 0 :(得分:2)

如错误消息中所述:

  1. 您的DemoBean类不可序列化。
  2. com.sun.xml.internal.ws.org.objectweb.asm.Label与wicket Label
  3. 无关