ZKSpring how to pass variables to the ZK zul from the Spring MVC controller?
i've beeing playing with zk a while and now comes serious things.
I've successfull integrated spring and zk and the routing
works as i use @controller
annotation.so far so good
Now i needed to call a webservice which return a list of objects
import org.springframework.ui.Model;
//.....
@RequestMapping("/accounts/personal/list")
public String list(Model model){
try {
ArrayOfAccount result = port.getAccounts( null, 0, 20);
//i thought with this i can grab the result collection.
List<IAccount> accounts = result.getIAccount();
model.addAttribute("accounts", accounts);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
return "accountslist";
}
the real problem is to get the object in the zul file.
<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/templates/mainlayout.zul"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<!--<?variable-resolver class="org.zkoss.spring.DelegatingVariableResolver"?>-->
<!--<?variable-resolver class="org.zkoss.spring.init.WebflowVariableResolver"?>-->
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
<window self="@{define(content)}" id="pAccountWin">
<label id="lblTest" value="click me" />
<div>
<listbox model="${c:l('accounts')}" id="lstAccount" multiple="true">
<listhead>
<listheader label="Account Name" />
<listheader label="Account Type" />
开发者_开发技巧 <listheader label="Mobile Phone" />
</listhead>
<listitem forEach="${c:l('accounts')}" value="${each}" >
<listcell label="${each.getAccountName()}" />
<listcell label="${each.getAccountType()}" />
<listcell label="${each.getMobilePhone()}" />
</listbox>
</div>
</window>
</zk>
it's not throwing an error but i feel like i'm not doing something right.And i also know that i can use GenrericForwardComposer to achieve the same wihtout "hassle"(i believe).this confuses me about whether i'm doing the right thing.
question 1:
How can i achive what i was trying to do as in passing the accounts variable to the frontend?question 2 : What's the best way using ZKspring(no webflows)? Spring Controller to do the routing and ForwardComposer to handle the ajax behaviors (ie events)? for example should a write the code to handle the ajax call when going solely the Spring MVC way?
question 3: i'm using listbox in this but i would need to do things from context menu on selected object.do you thing grid is suitable for it?
thanks for reading this.
Question 1 answer: ${c:l('accounts')
will retrieve a label value with key accounts
from i3label-properties file (normally used for internationalization in ZK). If you want to access a variable (normally a Java bean)
1. declare variable resolver at the top of your page using <variable-resolver class="org.zkoss.spring.DelegatingVariableResolver"?>
directive
2. access Java bean in ZUML using EL expressions for. eg. ${accounts}
Question 2 answer: I would recommend doing it ZK MVC way i.e extend you controllers from ZK GenericForwardComposer to handle events. You can always use spring to handle the lifecycle of these controller using Spring framework.
Question 3 answer: I don't think there is any advantage using grid over listbox in this scenario. In any case you can popup context menu on either grid row select event or listbox listitem select event.
精彩评论