Wicket循环输出
程序员文章站
2022-03-09 14:01:13
...
在Portal中动态布置Portlet,用到循环。
HTML
<wicket:fragment wicket:id="portal"> <wicket:fragment wicket:id="portlet"></wicket:fragment> </wicket:fragment>
Java (文件名:Column.java)
public class Column extends Panel { public Column(String id, List<PortletModel> portletList) { super(id, null); PortletLoop loop = new PortletLoop("portal", portletList.size(), portletList); add(loop); } private Portlet createPortlet(PortletModel portletModel) { if (portletModel.getPortletName().equals("AppPortlet")) return new AppPortlet(portletModel); else if (portletModel.getPortletName().equals("AppPortlet2")) return new AppPortlet2(portletModel); else return null; } private class PortletLoop extends Loop { List<PortletModel> portletList; public PortletLoop(String id, int size, List<PortletModel> portletList) { super(id, size); this.portletList = portletList; } protected void populateItem(LoopItem item) { Portlet app = createPortlet(portletList.get(item.getIndex())); if (app != null) { PortletBorder portletBorder = new PortletBorder("portlet", app); item.add(portletBorder); } } }; }
//END