Search code examples
zk

How do you reference a zul component with an dynamic id, like id="calendarDecorate_${vmStatus.index}"?


I have method in class

public class CalendarDecorate {
 public void setDays(final boolean checkDays){
  //code
}}

In my zul file, i have a own component for this class:

<div>
  <calendarDecorate id="calendarDecorate_${vmStatus.index}"</calendarDecorate>
  <combobox onChange="calendarDecorate_${vmStatus.index}.setDays(payment.Code)"/>
</div>

Is there a notation that allows this reference calendarDecorator_${vmPaymentStatus.index}.setDays(payment.Code) to work?


Solution

  • If there is just one <calendarDecorate>, you can just wire by component type

    @Wire("calendardecorate")

    Since you append an index in id, I suppose there are multiple <calendarDecorate>. You can Wiring a Collection and reference one of them with index, vmStatus.index.

    If you develop in MVVM pattern, usually you don't need to get a component reference. Just bind the corresponding property to the attribute e.g.

    <calendarDecorate days="@load(vm.payment.code">