Question

I have been struggling with this for a couple of days now and I can't seem to get it right. Here is my code:

<attribute name="onClick"><![CDATA[
Messagebox.show("Remove this file?", "Remove?", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION,
new EventListener() {
    public void onEvent(Event evt) {
        switch (((Integer)evt.getData()).intValue()) {
            case Messagebox.YES: someFunction(${each.Id}); break;
            case Messagebox.NO: break;
        }
    }
})
]]></attribute>

The above code is from a forEach cycle in a ZK ZUL page. It should generate a list of files and on every file you should have a "Delete" button. When you click on it a popup should come up and ask for confirmation. After you confirm it should pass the id to a function which from then handles everything.

I'm quite sure it's something really small I'm missing or not knowing.

Was it helpful?

Solution

There are two issues here.

  1. You cannot use EL in zscript. Rather, you have to access it through implicit object. For example,
    <window>
      <button label="${each}" forEach="apple, orange">
        <zscript>
      self.parent.appendChild(new Label("" + each));
        </zscript>
      </button>
    </window>
  1. However, each is available only in the page rendering. It is reset after evaluated. It means, you can't access it in the event listener. For example, the following won't work
    <window>
      <button label="${each}" forEach="apple, orange"
        onClick='alert(""+each)'/> 
    </window>

You have to store the each object first and then use it in the event listener.

You might take a look at ZK's reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top