当我调试List时,间接列表没有实例化。但是我觉得它在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...
答案 0 :(得分: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);
}
}
}
测试运行:1,失败:0,错误:0,跳过:0,已过去时间:0.032秒