Using Spring Variable Resolver
From Documentation
Purpose
Access Spring managed bean within ZK framework
DelegatingVariableResolver
You can access any spring managed beans by its id within ZK for eg. on ZUML page by declaring variable-resolver
for org.zkoss.zkplus.spring.DelegatingVariableResolver
at the top of your ZUML page.
Lets define a simple bean first
public class SimpleBean {
private String message;
public SimpleBean() {
}
public SimpleBean(String msg) {
this.message = msg;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Declare this bean in your applicationContext.xml Spring configuration file as below
<bean id="simpleBean" class="org.zkoss.zkspringessentials.beans.SimpleBean">
<constructor-arg value="Hello from a simple bean"></constructor-arg>
</bean>
Now using the org.zkoss.zkplus.spring.DelegatingVariableResolver
you can acess this bean in ZSCRIPT, EL expressions and ZK data binding annotations
Acess Spring beans in ZSCRIPT
You can access SimpleBean by its bean id in ZSCRIPT as shown below
<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
<zscript>
String msg = simpleBean.message;
</zscript>
<window title="Bean in ZScript" width="640px" border="normal" >
<vbox>
<hbox>
<label value="${msg}"></label>
</hbox>
</vbox>
</window>
</zk>