Search code examples
springzk

ZK - inject Spring beans directly into ZK beans


Is it possible to inject Spring beans directly into ZK backing beans?

In tutorials such as this I've found only an example, where application context was extracted manually from web application complex, which very unelegant and unflexible.


Solution

  • In fact, the VariableResolver is working, it is however hard to find, how to use it properly.

    First, I had to include header in .zul file:

    <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
    

    Then, use ${controllerBeanName} in apply attribute, f.e.

    <window id="win" title="Typy mieszkań" width="750px" border="normal"
          apply="${appartmentTypeController}">
    

    In my case, appartmentTypeController is bean extending GeneralForwardComposer, defined in spring context.