iframedata-bindingzkzk-grid

variable in iframe with zk


i have a for each in my zk page, and in the each i am creating a column, and in my column i need add a iframe, and to each frame i need pass as variable the label of the column.

I have something like:

<zk>
          <window title="Dynamic Columns" border="normal" width="1824px" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.DynamicColumnModel')">
<grid >

               <columns>
                  <column forEach="${vm.columnList}" label="${each}">

              <iframe 
        src="test.zul" />
                </column>
              </columns>
     </grid>
   </window>
</zk>

But i have an error when i include the page, and my first problem is that i do not know how can i pass a variable to each iframe.

And my java is something like:

public class DynamicColumnModel {

private List<String> columnList = new ArrayList<String>();
 private String texto="123";

@Init
public void init(){

    columnList.add("Dynamic Col A");
    columnList.add("Dynamic Col B");
    columnList.add("Dynamic Col C");
    columnList.add("Dynamic Col D");
}

public List<String> getColumnList() {
    return columnList;
}
public void setColumnList(List<String> columnList) {
    this.columnList = columnList;
}

 public String getTexto() {
    return texto;
}
public void setTexto(String texto) {
    this.texto = texto;
}


@Command
   public void mensaje(){

  }

}

Thanks


Solution

  • If your each is a String, which it appears to be as you set it as the column label, just go ahead and pass it as a URL parameter to the iframe.

        <window apply="org.zkoss.bind.BindComposer"
                viewModel="@id('vm') @init('pkg$.DynamicColumnModel')">
            <grid >
                <columns>
                    <column forEach="${vm.columnList}" label="${each}">
                        <iframe src="test.zul?myValue=${each}" />
                    </column>
                </columns>
            </grid>
       </window>
    

    Note that when you are using an iframe component, you are stepping outside ZK. True, the iframe itself points to a ZK page, but it's a not within the same ZK environment. The iframe could just as easily include www.google.com and so there is no specific ZK support for passing values to ZK pages included in this manner.

    If you're only including ZK pages and want to pass information to these pages more fluidly, you'll want to use ZK's include tag. Have a look at the documentation on how to pass values to included ZK pages.

    Edit
    If going the iframe route, you can access URL parameter values from test.zul using ZK's Execution class:

    Execution execution = Executions.getCurrent();
    execution.getParameter("myValue");