Wicket循环输出

阅读更多

在Portal中动态布置Portlet,用到循环。

 

HTML


  

 

Java (文件名:Column.java)

public class Column extends Panel {
	public Column(String id, List 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 portletList;

		public PortletLoop(String id, int size, List 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

你可能感兴趣的:(Wicket)