Exception thrown during Desktop.invalidate

asked 2012-06-25 12:24:44 +0800

ansancle gravatar image ansancle
317 9

This is a by-product of the issues on the Ipad where the ZK desktop cleanup does not happen since the webkit on the Ipad is not triggering the necessary javascript for ZK.
I am trying to manually cleanup the previous desktop when the user moves to a new page, unfortunately, when I call desktop.invalidate() I am getting nullpointer exceptions.

This code is executed when a new desktop is created (registered as a desktopinit listener), I have stored the previous desktop in the session and retrieve it so I can manually do cleanup when being accessed from the ipad. The call is not necessary from a PC since cleanup gets called normally through ZK.

	public void init(Desktop desktop, Object arg1) throws Exception
		Session session = desktop.getSession();
		String browserType = (String)session.getAttribute(DHnPageArguments.browsertype.toString());		
		// If we are on the Ipad, a new desktop being created means that we have gone to a new screen.
		// The old desktop should be cleaned up automatically by ZK, but since it does not get the correct javascript call
		// from the Ipad - it never happens. 
		// This code will check to see if we are on the Ipad and there is an old Desktop - call proxy cleanup
		// manually.
		if ((browserType != null) && (browserType.contains(DHnPageArguments.iPad.toString())))
			Desktop oldDesktop = (Desktop)session.getAttribute("desktop");
			if (oldDesktop != null)

And here is the exception which is thrown on oldDesktop.invalidate();

08:14:54,788 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web]...] (ajp-localhost- Servlet.service() for servlet zkLoader threw exception: java.lang.NullPointerException
at org.zkoss.zk.ui.impl.UiEngineImpl.addInvalidate(UiEngineImpl.java:271) [zk.jar:6.0.0]
at org.zkoss.zk.ui.impl.PageImpl.invalidate(PageImpl.java:429) [zk.jar:6.0.0]
at org.zkoss.zk.ui.impl.DesktopImpl.invalidate(DesktopImpl.java:1488) [zk.jar:6.0.0]
at com.dh.ui.common.desktop.DHzDesktopInitListener.init(DHzDesktopInitListener.java:69) [classes:]
at org.zkoss.zk.ui.util.Configuration.invokeDesktopInits(Configuration.java:829) [zk.jar:6.0.0]
at org.zkoss.zk.ui.impl.DesktopImpl.<init>(DesktopImpl.java:252) [zk.jar:6.0.0]
at org.zkoss.zk.ui.impl.AbstractUiFactory.newDesktop(AbstractUiFactory.java:81) [zk.jar:6.0.0]
at org.zkoss.zk.ui.http.WebManager.newDesktop(WebManager.java:472) [zk.jar:6.0.0]
at org.zkoss.zk.ui.http.WebManager.getDesktop(WebManager.java:453) [zk.jar:6.0.0]
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:185) [zk.jar:6.0.0]
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:134) [zk.jar:6.0.0]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:679) [rt.jar:1.6.0_22]


delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-07-04 03:06:23 +0800

benbai gravatar image benbai
2228 6

updated 2012-07-04 03:12:14 +0800

Hi ansancle,

The 'invalidate' denotes to rerender/redraw the old desktop, it is better do not redraw the old desktop after it is cleaned up.


link publish delete flag offensive edit

answered 2012-07-05 18:48:42 +0800

ansancle gravatar image ansancle
317 9

what is the best way then to force a cleanup of a desktop? I have not found another way to do this - again this is only a problem when accessing from the Ipad,

link publish delete flag offensive edit

answered 2012-07-06 01:57:39 +0800

benbai gravatar image benbai
2228 6

updated 2012-07-06 02:17:31 +0800

Hi Andy,

Please refer to the document:

ZK will clean up desktop automatically if the number of desktop hits the limitation 'max-desktops-per-session' in session config or idle time of desktop hits the 'desktop-timeout' in desktop-config, the 'cleanup' here is to clean some specific extra data.

For example, assume you have the fragment when init:

dataMap.put(userId, usersHugeData);

then you may want remove it while desktop cleanup

if (isLoggedOut(userId))

For more information, please refer to
ZK Configuration Reference/zk.xml/The session-config Element
ZK Configuration Reference/zk.xml/The desktop-config Element

If you really want to remove a desktop manually, you may try something like below:

	<button label="test">
		<attribute name="onClick">
			Desktop dt = self.getDesktop();
			WebApp wapp = dt.getWebApp();

However, it is Strongly recommended NOT to do this.


link publish delete flag offensive edit

answered 2012-07-12 14:26:58 +0800

ansancle gravatar image ansancle
317 9

thanks for the information on how to finally do it. I am familiar with all of the timeout settings and may go back to setting a very large timeout (greater than my page timeouts), so when it's access from the Ipad they will get cleaned up.

Thanks again!!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2012-06-25 12:24:44 +0800

Seen: 227 times

Last updated: Jul 12 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More