Theme:
Processing...
Description & Source Code

Portal layout offers users the freedom to personalize and outline how a set of selected portlets should appear on a page. Users can perform operations such as drag and drop, collapse and expand, minimize and maximize on each portlet.

Updated: Auto save portlet position into session. For more technology details, please refer to our Component Reference - PortalLayout

portal_layout.zul
<div apply="demo.layout.portal_layout.PortalLayoutController">
	<portallayout id="portalLayout" maximizedMode="whole">
		<portalchildren style="padding: 5px" width="30%">
			<panel id="calendar" title="Calendar" border="normal" collapsible="true" closable="true" maximizable="true" style="margin-bottom:10px">
				<panelchildren>
					<calendar/>
				</panelchildren>
			</panel>
			<panel id="translate" title="Translate" border="normal" collapsible="true" closable="true" maximizable="true" style="margin-bottom:10px">
				<panelchildren>
					<include src="/widgets/layout/portal_layout/incl/translate.zul"/>
				</panelchildren>
			</panel>
		</portalchildren>

		<portalchildren style="padding: 5px" width="40%">
			<panel id="todo" title="ToDo" border="normal" collapsible="true" closable="true" maximizable="true" style="margin-bottom:10px">
				<panelchildren>
					<include src="/widgets/layout/portal_layout/incl/todo.zul"/>
				</panelchildren>
			</panel>
			<panel id="clock" height="250px" title="Clock" border="normal" collapsible="true" closable="true" maximizable="true" style="margin-bottom:10px">
				<panelchildren>
					<include src="/widgets/layout/portal_layout/incl/clock.zul"/>
				</panelchildren>
			</panel>
		</portalchildren>

		<portalchildren style="padding: 5px" width="30%">
			<panel id="weather" title="Weather" border="normal" collapsible="true" closable="true" maximizable="true" style="margin-bottom:10px">
				<panelchildren>
					<include src="/widgets/layout/portal_layout/incl/weather.zul"/>
				</panelchildren>
			</panel>
		</portalchildren>
	</portallayout>
</div>
PortalLayoutController.java
package demo.layout.portal_layout;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zkmax.zul.Portallayout;
import org.zkoss.zul.Panel;

public class PortalLayoutController extends SelectorComposer<Component> {

	@Wire
	private Portallayout portalLayout;
	
	@Listen("onPortalMove = #portalLayout")
	public void saveStatus() {
		int i = 0;
		for (Component portalChild : portalLayout.getChildren()) {
			List<String> portletIds = new ArrayList<String>();
			for (Component portlet : portalChild.getChildren())
				portletIds.add(portlet.getId());
			Executions.getCurrent().getSession().setAttribute("PortalChildren" + i++, portletIds);
		}
	}
	
	@Listen("onCreate = #portalLayout")
	public void initStatus() {
		
		List<? extends Component> panelchildren = portalLayout.getChildren();
		for (int i = 0; i < panelchildren.size(); i++) {
			List<String> panelIds = (List<String>) Executions.getCurrent().getSession().getAttribute("PortalChildren" + i);
			if (panelIds != null) {
				for (String panelId : panelIds) {
					Panel newPanel = (Panel)portalLayout.getFellow(panelId);
					if (panelchildren.size() > 0)
						panelchildren.get(i).insertBefore(newPanel, panelchildren.get(0));
					else
						newPanel.setParent(panelchildren.get(i));
					
				}
			}
		}
	}
}