0

Desktop null for autowired components in Spring loaded composers

asked 2011-06-16 04:14:25 +0800

jarnisb gravatar image jarnisb
36 1

Hi Guys

I am working on a ZK app where the composers for individual pages are Spring beans (attached by using apply="${beanName}"). The composers all extend GenericForwardComposer and a number of components are autowired to fields in the composer class. When a page is loaded the first time, everything works as expected. However, if a page is reloaded, the desktop variable of the autowired components is set to null (which leads to NullPointerExceptions and UiException: You cannot access components belong to other desktop).

The problem disappears if I change the .zul file to use the composer class directly instead of using the spring bean.

All the composer beans have scope="session", thou I have also tried with "singleton", which does not solve the problem and "prototype" which breaks the autowiring.

We are using
ZK v. 5.0.7
Spring v. 3.0.0.RELEASE

There are a number of old threads describing this problem (incl http://www.zkoss.org/forum/listComment/12114 and http://www.zkoss.org/forum/listComment/8092, but none of them seem to describe the problem precisely, or to offer a good solution.

If needed, I will gladly post example code (the code I used to identity the problem include too much unrelated functionality to just post unedited). As this seems to be a very serious issue and limitation to the usefullness of using Spring in combination with ZK, I would very much appreciate a solution, or at least a good workaround.

Thanks in advance,

Jarnis Bertelsen
Developer
Telmore A/S

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-06-16 08:04:09 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-06-16 08:04:34 +0800

Why does scope 'prototype' breaks the autowiring ?? Do you mean the binder ?

  . . . and "prototype" which breaks the autowiring.

link publish delete flag offensive edit

answered 2011-06-17 04:11:19 +0800

jarnisb gravatar image jarnisb
36 1

After looking a bit into the problem with prototypes, it turned out that the problem was related to the way we wired the components. Instead of referring to the spring bean only in the top-level component of each zul file and using ${toplevelcomponentid$composer.property} we were using ${beanName.property} other places in the page. I changed this, and it fixed the wireing problem (as well as the constructor being called repeatedly).

It appearantly also fixes the problem with the null-desktops, so I guess that it's a usable workaround. I would still prefer the scope for the composer to be "session" to be able to keep state there, as well as avoid extra instantiation when the user switches components, but it is not a show-stopper.

Thanks,
Jarnis

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

Follow

RSS

Stats

Asked: 2011-06-16 04:14:25 +0800

Seen: 764 times

Last updated: Jun 17 '11

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