23.12.2012 Views

ZK Developer's Guide

ZK Developer's Guide

ZK Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ 95 ]<br />

Chapter 4<br />

With the doOverlapped method, we get the ability to move the window around.<br />

However, when we click on add testdata to add some data to the main listbox, we<br />

enforce a reload of the page because of Executions.sendRedirect("index.zul")<br />

at the end of the action of add testdata. After reload, the position of rememberWindow<br />

is lost. To solve this problem, we have to store the position of the window component<br />

in the session, and restore that position in the construction phase of the window. To<br />

implement this feature, we have to extend org.zkoss.zul.Window.<br />

public class RememberWindow extends Window implements EventListener<br />

{<br />

/******************************************************************<br />

********<br />

* Internal Constants<br />

*******************************************************************<br />

*******/<br />

private final static String LEFT = "LEFT";<br />

private final static String TOP = "TOP";<br />

/******************************************************************<br />

********<br />

* Instance variables<br />

*******************************************************************<br />

*******/<br />

private boolean setBySession = false;<br />

private String firstTop;<br />

private String firstLeft;<br />

/******************************************************************<br />

********/<br />

/**<br />

* Constructor.<br />

* A event listener for the event onMove is registered.<br />

*/<br />

public RememberWindow()<br />

{<br />

this.addEventListener("onMove", this);<br />

// Restore the left position from the session if avaiable<br />

if (Sessions.getCurrent().getAttribute(LEFT) != null)<br />

{<br />

this.setLeft((String) Sessions.getCurrent().getAttribute(LEFT));<br />

this.setBySession = true;<br />

}<br />

// Restore the top position from the session if avaiable<br />

if (Sessions.getCurrent().getAttribute(TOP) != null)<br />

{<br />

this.setTop((String) Sessions.getCurrent().getAttribute(TOP));<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!