欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

相关标签: Wicket