-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In view model I have:
TreeModel files= new DefaultTreeModel( new DefaultTreeNode(null, new DefaultTreeNode[] { new DefaultTreeNode(new FileInfo("/doc", "Release and License Notes")), new DefaultTreeNode(new FileInfo("/dist", "Distribution"), new DefaultTreeNode[] { new DefaultTreeNode(new FileInfo("/lib", "ZK Libraries"), new DefaultTreeNode[] { new DefaultTreeNode(new FileInfo("zcommon.jar", "ZK Common Library")), new DefaultTreeNode(new FileInfo("zk.jar", "ZK Core Library")) }), new DefaultTreeNode(new FileInfo("/src", "Source Code")), new DefaultTreeNode(new FileInfo("/xsd", "XSD Files")) }) }
In zul I have:
<tree model="${files}"> <treecols> <treecol label="Path"/> <treecol label="Description"/> </treecols> <template name="model"> <treeitem context="menupopup"> <treerow> <treecell label="${each.data.path}"/> <treecell label="${each.data.description}"/> </treerow> </treeitem> </template> </tree>
In version 6.0.0 all works ok but when I updated to version 6.0.1 when I try to deploy the children of a node in the tree the following error occurs: "Property 'data' not found in the type org.zkoss.bind.impl.ReferenceBindingImpl"
Thanks in advance.
.
It is a bit trouble for a new to zkbind2 user to know when to use @ and when to use $
${} is original EL of zk, it runs when creating a zul content to components.
for the case, <component attr="${somevalue}"/>the value is got by 'somevalue' and set to component.attr by reflection directly. (so in original EL, using attributes.whatever doesn't work)
You usually do this when you use MVC pattern to develop you application and for load only-once data.
@annotation is ZK annotation syntax and zkbind use it to help developer sets binding expression when using MVVM pattern to develop application, it is since ZK 6.0.0 , it runs after a zul content created (in afterCompose precisely)
for the case <component attr="@load(somevalue)"/>the value is got by 'somevalue' and set to component.attr by EL too.
so you can get/set any chain attribute by Bind EL if instance has it (EL did it).
in your case, if you want to set label of 'catlog....' by ${} to a custom attribute, you have to use <custom-attributes whatever="$ {c: l ('catalog.doc.tree.comments')}"></custom>
a simple way to choose when to use ${} and when @ for me.
it the value is static, loads only once, not comes from any instance that is related to object of MVVM development pattern. use ${}
if the value comes from some objects of MVVM pattern, the use @load, @bind...etc
Hello Dennis,
sorry, that was my mistake. I also wanted to set additional custom attributes via EL expressions. For example, in order to set country-specific strings.
attributes.whatever = "$ {c: l ('catalog.doc.tree.comments')}"
In these cases the error occur.
The reason for the IllegalArgumentException is the combination fom listbox and model: group. See also forum thread "ZK 6 bind and model: group"
Thank you for your help ... and your patience :-)
Kai
it goes by the EL way, not zkbind magic, what is your zul syntax and the exception stack print?
Works this feature to set attribute only with listcell items? I have tried it with listgroup and tree. I get the error message "Method setAttributes.whatever not found for class org.zkoss.zul.Listgroup/Tree
java.lang.IllegalArgumentException"
Kai
this is kind of EL tricky, zkbind use EL to set/get data,
<listitem attributes.whatever="@load(each)"></listitem>
in this case, it get data from each, and set to listitem.attributes.whatever(it do code like listitem.getAttributes().put('whatever',value) in java)
Hello Dennis,
in my concrete case I would like to use each.data as custom attribute.
... <listitem> <custom-attributes whatever="${each.data}" scope="component"/> <listcell label="@load(each.data)"/> </listitem> ...
This is not possible with bind mechanism. Do you have a solution for it?
Kai
this is a bug when using zkbind(ex. @load) with zk el(${}) on reference or element of a collection.
for now, you could use <listcell label="@load(each.data)"> to solve it.
I also created a issue here : http://tracker.zkoss.org/browse/ZK-1188
Hello Monty Pan,
i have same problem after upgrade. Here is a test case to reproduce the problem.
I use ZK PE
Kai
<?xml version="1.0" encoding="UTF-8"?> <?page title="Auto Generated index.zul"?> <zk> <zscript><![CDATA[ ListModelList lm0= new ListModelList(); class A { public A(String s, Long v) { s_= s; v_= v; } public String getData() { return s_; } String s_= null; Long v_= null; } // Make first entry in ListModel ListModelList list= new ListModelList(); list.add(new A("RE: Bandbox Autocomplete Problem", 0L)); list.add(new A("RE: It's not possible to navigate a listbox' ite", 1L)); list.add(new A("RE: FileUpload", 2L)); lm0.add(new Object[] {"Today", list }); // Make second entry in ListModel list= new ListModelList(); list.add(new A("RE: Opening more than one new browser window", 10L)); list.add(new A("RE: SelectedItemConverter Question", 11L)); lm0.add(new Object[] { "Yesterday", list }); // Make third entry in ListModel list= new ListModelList(); list.add(new A("RE: Times_Series Chart help", 30L)); list.add(new A("RE: SelectedItemConverter Question", 31L)); lm0.add(new Object[] { "Last week", list }); class VM { public ListModel getLm0() { return lm0; } } ]]></zscript> <window title="Hello World!!" border="normal" width="800px" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" > <label value="You are using: ${desktop.webApp.version}"/> <listbox id="lb" model="@load(vm.lm0)" > <listhead> <listheader hflex="3"/> <listheader hflex="6"/> </listhead> <template name="model"> <listitem> <custom-attributes inner_list="${each[1]}" scope="component"/> <listcell> <label value="@load(each[0])"/> </listcell> <listcell> <listbox model= "@load(inner_list)"> <template name="model"> <listitem> <listcell label="${each.data}"> </listcell> </listitem> </template> </listbox> </listcell> </listitem> </template> </listbox> </window> </zk>
I test ZK demo code in ZK-bin-6.0.1 , it's work fine.
Can you give more detail information?
Regards,
Monty Pan
Asked: 2012-05-28 16:53:35 +0800
Seen: 280 times
Last updated: Jun 13 '12