Revision history [back]

click to hide/show revision 1
initial version

answered 2011-02-09 16:33:04 +0800

xcom gravatar image xcom

MY TERRY MASTER ZK my index main :

<?page id="indexP" contentType="text/html;charset=UTF-8"?>
<?init class="util.WindowDataBinderInit"?>
<zk>
    <window id="main" width="100%" height="100%"
        apply="IndexViewCtrl">
        <borderlayout>
            <west size="200px" splittable="true" flex="true"
                collapsible="true" title="Menu">
                <tree id="tree" width="100%" height="100%" forward="onSelect=onSelectTree()">

                    <treechildren width="100%" height="100%">
                        <treeitem>
                            <treerow>
                                <treecell label="Test" />
                            </treerow>
                            <treechildren>
                                <treeitem>
                                    <treerow>
                                        <treecell label="Test One" />
                                    </treerow>
                                </treeitem>

                            </treechildren>
                        </treeitem>
                    </treechildren>
                </tree>
            </west>
            <center flex="true">
                <div id="contentDiv">
                    <tabbox id="tb" height="550px" width="100%">
                        <tabs />
                        <tabpanels />
                    </tabbox>
                </div>
            </center>

        </borderlayout>
    </window>
</zk>

my controller index:

package com.webui.index;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;
import org.zkoss.zul.Tree;
import org.zkoss.zul.Window;

import com.webui.macro.MacroUbicacion;
import org.zkoss.zkplus.spring.SpringUtil;
import com.Controlador


public class IndexViewCtrl extends GenericForwardComposer {

    private static final long serialVersionUID = 1L;

        private Window win;
    private Tabbox tb;
    private Tree tree;
    private Controlador controlador;


    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        controlador=(Controlador)SpringUtil.getBean("controlador");

    }

    public void onClick$tree(Event event) {
        Map<String,Object> miMapa = new HashMap<String, Object>();
        miMapa.put("controlador",this.controlador);
        Tabpanels tabpanels = tb.getTabpanels();
        Tab tab = new Tab(tree.getSelectedItem().getLabel());
        tab.setClosable(true);
        Tabs tabs = tb.getTabs();
        tabs.appendChild(tab);
        Tabpanel tp = new Tabpanel();
        tp.appendChild(Executions.createComponents("page.zul", null,miMapa));
        tabpanels.appendChild(tp);
    }

my index use class:

package util;

import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.util.Initiator;
import org.zkoss.zk.ui.util.InitiatorExt;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.Window;

public class WindowDataBinderInit implements Initiator, InitiatorExt{

    @Override
    public void doAfterCompose(Page arg0, Component[] arg1) throws Exception {
          for ( Component c : arg1) {
                if ( c instanceof Window ) {
                    AnnotateDataBinder binder = new AnnotateDataBinder(c, true);
                    c.setAttribute("binder", binder, true);
                    binder.loadAll();
                }
            }

    }

    @Override
    public void doAfterCompose(Page arg0) throws Exception {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean doCatch(Throwable arg0) throws Exception {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void doFinally() throws Exception {
        // TODO Auto-generated method stub

    }

    @Override
    public void doInit(Page arg0, Map arg1) throws Exception {
        // TODO Auto-generated method stub

    }

}

my page.zul (n this page is what I am calling from the main, the same listbox in several tabpanel)

<zk xmlns="http://www.zkoss.org/2005/zul"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">  
<?page id="myPage" ?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window width="640px" border="normal"
        apply="com.Ctrl">
        <listbox id="lb" model=>(IR A) 
            selectedItem="@{Ctrl.myObject}" >
            <listhead>
                <listheader label="Name" />
            </listhead>         
        </listbox>
    </window>
</zk>

IR A : IF model= " @ {CODE_ONE} " IN PAGE.ZUL THEN NOT SHOW DATA=> NOTHING WORKS

IR A : IF model= "@ {CODE_TWO}" IN PAGE.ZUL THEN =>WORK =>SHOW DATA=>SELECTEDINDEX WORK=>SELECTEDITEM NOT WORKS!!!!!! IS NULL

CODEONE=Ctrl.modelo //IN MANUAL NOT WOKR CODEtwo=$Ctrl.modelo//ADD THE $ WORK SHOW DATA

Controller page.zul

package com;

import java.util.List;
import java.util.Map;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.Controlador;
import com.MyObject;
import com.webui.macro.MacroUbicacion;


@SuppressWarnings("serial")
public class Ctrl extends GenericForwardComposer{


    //controller from database
        private Controlador controlador;
       //param 
        private Map<String,Object> map;
       //list my Object 
        private List<MyObject> modelo;
       //my object select 
        private MyObject myObject;
        //listbox from ui  page.zul
         private Listbox lb;


        @Override
    public void doAfterCompose(Component comp) throws Exception {
        //call cons super class is ok
                super.doAfterCompose(comp);
                //get map is ok
            map = Executions.getCurrent().getArg();
            controlador=(Controlador) map.get("controlador");
             //from  getListMyObject database is ok
                 modelo=controlador.getListMyObject();//is ok

                lb.setItemRenderer(new ListitemRenderer() {

                @Override
                public void render(Listitem item, Object data) throws Exception {
                    // TODO Auto-generated method stub
                    final MyObject d=(MyObject)data;//is ok
                    new Listcell(d.getName()).setParent(item);//is ok

                }
            });//is ok




    }

    //event seleted not work
       public void onSelect$lb(Event event){
        alert(myObject.getName()); //NOT WORK IS NULL
    }


    //get and set model
       public List<MyObject> getModelo() {
        return modelo;
    }

    public void setModelo(List<MyObject>  modelo) {
        this.modelo = modelo;
    }


    //get and set myObject selected -->selectedItem="@{Ctrl.myObject}" >
       public myObject getMyObject () {
        return dispositivo;
    }

    public void seMyObject(MyObject  myObject) {
        this.myObject = myObject;
    }
}

TERRY IS MY JESUS, HELP BECAUSE NOT WORK SELETEDITEM AND MODEL HELPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP CALL 999 JA

PLEASE LISTEN YOU TERRY, MY JESUS

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More