From Documentation

Jump to: navigation, search




There are two ways to access Spring-Managed beans in your ZUML page. One is using variable-resolver, and the other is using SpringUtil. Which to use depends on your usage, in the ZUML page, we suggest you to use variable-resolver.

Using variable-Resolver

Simply declare the variable-resolver for org.zkoss.zkplus.spring.DelegatingVariableResolver on top of your ZUML page, then, in the rest of your page, you can access any Spring-Managed beans directly using its bean-id.

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
  <window>
  <grid>
    <rows>
     <row forEach="${DataSource.elementsList}">
       <label value="${each}"/>
     </row>
    </rows>
  </grid>
 </window>

variable-resolver will look-up the bean named DataSource automatically for you, and returned a list to the forEach loop.

Using SpringUtil

org.zkoss.zkplus.spring.SpringUtil is a utility class which allows you to get Spring-managed beans with ease.

 <window>
 <zscript><![CDATA[	
  import org.zkoss.zkplus.spring.SpringUtil;
  import test.*;
  
  DataSource dataSource = SpringUtil.getBean("DataSource");
  List list = dataSource.getElementsList();
]]>
 </zscript>
  
  <grid>
    <rows>
     <row forEach="${list}">
       <label value="${each}"/>
     </row>
    </rows>
  </grid>
 </window>

Where the forEach loop is looping over the collection to print the ${each} attribute on each object in the collection.



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.