-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm a total n00b here.
Here's what I'm trying to do:
<template name="model">
<listitem>
<listcell label="@load(each.clientId)"/>
<listcell label="@load(each.partId)"/>
...
This shows me the clientId, partId, etc. However, instead of showing the clientId, I want to show the client name, which is not part of my model. I created a method in the ViewModel to get this name from an id passed as a parameter.
Now, I hoped to be able to use something like:
<listcell label="@load(each.getClientName(each.clientId))"/>
But, as you can guess, it fails miserably...
Can someone give me a hint please. I really need it...
There can be a plenty of way to do this one thing i can suggest you to create a class name something DataBean which will contain all the records which you will want to display to user.So your DataBean Class Could be something like this
public class DataBean{
String name;
String parentID;
//Getter,Setter of above varaible
}
Now when you are creating your model give this DataBean class to the model something like this
List<DataBean> dataList = new ArrayList<>();
here you can see dataList would contain all the record of type DataBean class so you do not need to write any complex logic into the ZUL file.
Rather than you can write logic in Java Class to set the values in DataBean class.
The following example works and uses the function getClientName.
Kai
<?xml version="1.0" encoding="UTF-8"?>
<zk> <style> .red { color: red; } </style> <zscript>
class A
{
public A(String s, Long v, Boolean is_group) { s_= s; v_= v; is_group_= is_group; }
public String getLabel() { return s_; }
public Boolean isGroup() { return is_group_; }
public Long getValue() { return v_; }
public String getClientName(Long v) { return s_+ " -- "+ v.toString(); }
String s_= null;
Long v_= null;
Boolean is_group_= null;
}
lm.add(new A("Today", 1L, Boolean.TRUE));
lm.add(new A("RE: Bandbox Autocomplete Problem", 2L, Boolean.FALSE));
lm.add(new A("RE: It's not possible to navigate a listbox' ite", 3L, Boolean.FALSE));
lm.add(new A("RE: FileUpload", 4L, Boolean.FALSE));
lm.add(new A("Yesterday", 10L, Boolean.TRUE));
lm.add(new A("RE: Opening more than one new browser window", 11L, Boolean.FALSE));
lm.add(new A("RE: SelectedItemConverter Question' ite", 12L, Boolean.FALSE));
lm.add(new A("Last week", 100L, Boolean.TRUE));
lm.add(new A("RE: Times_Series Chart help", 101L, Boolean.FALSE));
lm.add(new A("RE: SelectedItemConverter Question", 102L, Boolean.FALSE));
class VM
{
public ListModel getListModel() { return lm; }
}
]]></zscript>
<window id="win" title="Window ZK6 dynamic template" border="normal" width="600px"
apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >
<listbox model="@bind(vm.listModel) @template(each.isGroup() ? 'group_model' : 'item_model')">
<listhead>
<listheader hflex="3" label="Column 1"/>
<listheader hflex="1" label="Column 2"/>
</listhead>
<template name="group_model">
<listgroup open="true" label="@load(each.label)"/>
</template>
<template name="item_model">
<listitem vflex="1">
<listcell>
<label value="@load(each.getClientName(each.value))"/>
</listcell>
<listcell>
<label value="@load(each.value)"/>
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>
Asked: 2013-07-25 16:01:42 +0800
Seen: 40 times
Last updated: Jul 26 '13