My project have some code below as this. The last time people who use this framework have left this company. Please some one explain below code to me. What is the meaning of self
and @each
.
I don't know below listcell @item.areaNo
the prefix item is from self="@{each='item' }
or value="@{item }
. And I really don't know what self="@{each='item' }
means.
<listitem self="@{each='item' }" value="@{item }"
forward="onDoubleClick=onDoSelectItem,onClick=onDoChkDelete">
<listcell>
<fixedmodecheckbox label="${labels.delete}" />
</listcell>
<listcell label="@{item.areaNo}" />
<listcell label="@{item.formattedLocationNo}" />
<listcell label="@{item.storerCode.storerCode}" />
<listcell label="@{item.itemCode.itemCode}" />
<listcell label="@{item.itemCode.itemName }" />
<listcell label="@{item.stratedgyValue_2 }" />
<listcell label="@{item.palletNo }" />
<listcell label="@{item.itemCode.packCode.packCode }" />
<listcell label="@{item.stockCaseQty }" />
<listcell label="@{item.stockPieceQty }" />
<listcell label="@{item.allocationCaseQty }" />
<listcell label="@{item.allocationPieceQty }" />
</listitem>
Your code is using the "old databinding" syntax for rendering collections of objects. It's still mentioned in the ZK 5 Developer's Reference, page 139 (available from the archive section). Even though deprecated since at least 6 or 7 years it's still part of ZK to support legacy code as in your case.
What it does (and I am also guessing a bit since this appears rarely in old code) is:
each
is the current object of the collection, which is given a name item
, so that it's accessible in binding expressions inside this repeated component self
.
value="@{item}"
will then simply call listitem.setValue(item) so that your listitem, remembers the object it's associated with.
I agree the syntax is weird and I assume that's why this has been deprecated and superseded by the new binding annotation syntax since ZK 6 or 6.5 (you can see a similar example at the bottom of this current documentation page).
However upgrading is not a drop-in replacement and requires quite some refactoring of your java code. That's why this kind of code keeps sticking around.