-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
Why does scope 'prototype' breaks the autowiring ?? Do you mean the binder ?
. . . and "prototype" which breaks the autowiring.
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
Asked: 2011-06-16 04:14:25 +0800
Seen: 764 times
Last updated: Jun 17 '11