Accessing Spring Bean in the ZUML page"

From Documentation
m (correct highlight (via JWB))
 
Line 1: Line 1:
 
{{ZKDevelopersGuidePageHeader}}
 
{{ZKDevelopersGuidePageHeader}}
  
There are two ways to access Spring-Managed beans in your ZUML page. One is using <tt>variable-resolver</tt>, and the other is using <tt>SpringUtil</tt>. Which to use depends on your usage, in the ZUML page, we suggest you to use <tt>variable-resolver</tt>.  
+
There are two ways to access Spring-Managed beans in your ZUML page. One is using <code>variable-resolver</code>, and the other is using <code>SpringUtil</code>. Which to use depends on your usage, in the ZUML page, we suggest you to use <code>variable-resolver</code>.  
  
 
=== Using variable-Resolver ===
 
=== Using variable-Resolver ===
Simply declare the <tt>variable-resolver</tt> for <tt>org.zkoss.zkplus.spring.DelegatingVariableResolver</tt> 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.
+
Simply declare the <code>variable-resolver</code> for <code>org.zkoss.zkplus.spring.DelegatingVariableResolver</code> 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.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 19: Line 19:
 
</source>  
 
</source>  
  
<tt>variable-resolver </tt>will look-up the bean named <tt>DataSource</tt> automatically for you, and returned a list to the <tt>forEach</tt> loop.
+
<code>variable-resolver </code>will look-up the bean named <code>DataSource</code> automatically for you, and returned a list to the <code>forEach</code> loop.
  
 
=== Using SpringUtil ===
 
=== Using SpringUtil ===
<tt>org.zkoss.zkplus.spring.SpringUtil</tt> is a utility class which allows you to get Spring-managed beans with ease.  
+
<code>org.zkoss.zkplus.spring.SpringUtil</code> is a utility class which allows you to get Spring-managed beans with ease.  
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 45: Line 45:
 
</source>
 
</source>
 
   
 
   
Where the <tt>forEach</tt> loop is looping over the collection to print the <tt>${each}</tt> attribute on each object in the collection.
+
Where the <code>forEach</code> loop is looping over the collection to print the <code>${each}</code> attribute on each object in the collection.
 
{{ ZKDevelopersGuidePageFooter}}
 
{{ ZKDevelopersGuidePageFooter}}

Latest revision as of 10:38, 19 January 2022

Accessing Spring Bean in the ZUML page


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


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.


Last Update : 2022/01/19

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