1

当我调试列表时说,间接列表未实例化。但是我在 JPA 中偷懒了。它不在 Listview 中呈现,但它应该有节点。我错过了什么吗?

//.....code......
private ListView<String> reqs; // Requirements
private Label lblreqs;  //Label for repeat requirements
//...code...
    final LigaBaseball lbb = LigaBBServ.buscarPorID(Integer
            .parseInt(idLiga)); //Get Baseball league from database

    if (lbb == null || pageParameters == null
            || pageParameters.get("idLiga") == null)
        throw new RestartResponseException(VerLigas.class); //If null redirect.
//...code...

    add(reqs = new ListView<String>("reqs", new ListModel<String>(lbb.getRequisitos()))//LAZYly get List from LigaBaseball(BaseballLeague) {
        @Override
        protected void populateItem(ListItem<String> item) {
        /*When I debug item is null
*/
            item.add(lblreqs = new Label("lblreqs", (item.getModelObject())));
        }
    });

//...code...
4

1 回答 1

1

好吧...根据从您发布的代码创建的这个(相当简约的)UnitTest,确实如此,但也许我错过了重点......

package net.unbewaff;

public class DemoTestCase {

    private WicketTester tester = new WicketTester();
    private Panel panel = new MyPanel("panel");

    @Test
    public void testIt() {
        tester.startComponentInPage(panel);
        tester.assertComponent("panel", Panel.class);
        tester.assertComponent("panel:reqs", ListView.class);
        tester.assertComponent("panel:reqs:0", ListItem.class);
        tester.assertLabel("panel:reqs:0:lblreqs", "1");
        tester.assertComponent("panel:reqs:1", ListItem.class);
        tester.assertLabel("panel:reqs:1:lblreqs", "2");
        tester.assertComponent("panel:reqs:2", ListItem.class);
        tester.assertLabel("panel:reqs:2:lblreqs", "3");
        tester.assertComponent("panel:reqs:3", ListItem.class);
        tester.assertLabel("panel:reqs:3:lblreqs", "4");
    }

    private final class MyPanel extends Panel {

        private MyPanel(String id) {
            super(id);
        }

        public void onInitialize() {
            ListView<String> reqs;

            final LigaBaseball lbb = new LigaBaseball();

            reqs = new ListView<String>("reqs", new ListModel<String>(lbb.getRequisitos())) {

                protected void populateItem(ListItem<String> item) {
                    item.add(new Label("lblreqs", (item.getModelObject())));
                }
            };

            add(reqs);

            super.onInitialize();
        }
    }

    class LigaBaseball {

        public List<String> getRequisitos() {
            String[] a = { "1", "2", "3", "4" };
            return Arrays.asList(a);
        }
    }
}

测试集:net.unbewaff.DemoTestCase

测试运行:1,失败:0,错误:0,跳过:0,经过时间:0.032 秒

于 2012-06-11T12:37:40.187 回答