0

Listbox get item from java.util.List

asked 2011-02-08 17:57:17 +0800

xcom gravatar image xcom
564 3

updated 2011-02-08 17:58:53 +0800

Hello:

as I can get the item from listbox and I have associated the model follows

class MyObject{
    String name;
    //get and set
}

mi zul

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk xmlns="http://www.zkoss.org/2005/zul">
	<window width="100%" height="100%" border="normal"
		apply="ViewCtrl">
		<listbox id="lb" selectedItem="@{ViewCtrl.myObject}" model="@<DispositivoViewCtrl.model>">
			<listhead sizable="true">
				<listheader label="Name" />
			</listhead>
			<listitem self="@{each=myObject}">
			<listcell label="@{myObject.name}" />
			</listitem>
        	</listbox>
	</window>
</zk>

my controller


import java.util.List;

import org.zkoss.spring.SpringUtil;


public class  ViewCtrl extends GenericForwardComposer {



	private static final long serialVersionUID = -831345075170933131L;
	private ControllerSpring cs;
	private List<MyObject> model;
	private myObject MyObject;



	public MyObject getmyObject() {
		return myObject;
	}

        public MyObject setmyObject(MyObject myObject) {
		this.myObject=myObject;
	}

	

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


	public void onSelect$lb(){
		
		alert(myObject.name); //is null, because???

	}



	public List<MyObject> getModel() {
		return model;
	}



	public void setModel(List<MyObject> model) {
		this.model = model;
	}




}


how I can retrieve the selected object???

plese

thanks in advance

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2011-02-09 03:03:17 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-09 03:04:00 +0800

it's case sensitive

old

public MyObject getmyObject() {
		return myObject;
	}

        public MyObject setmyObject(MyObject myObject) {
		this.myObject=myObject;
	}

new

public MyObject getMyObject() {
		return myObject;
	}

        public MyObject setMyObject(MyObject myObject) {
		this.myObject=myObject;
	}

best
Stephan

link publish delete flag offensive edit

answered 2011-02-09 06:06:13 +0800

xcom gravatar image xcom
564 3

master:

change, but
9-02-2011 09:05:05 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1253
GRAVE: >>java.lang.NullPointerException is null, because???

link publish delete flag offensive edit

answered 2011-02-09 06:15:18 +0800

xcom gravatar image xcom
564 3

I could do a simple example to me using objecto

link publish delete flag offensive edit

answered 2011-02-09 09:15:27 +0800

xcom gravatar image xcom
564 3

updated 2011-02-09 09:17:37 +0800

TERRY:

Because I have to spend the index to him to obtain the objecto in order that it works, because I it cannot utlizar directly

case 1:

public void onSelect$lb(Event event){
		int index=lb.getSelectedIndex();
		myObject=(MyObject) modelo.get(index);
		alert(myObject.getName());
	}

WORKKKKKKKKKKKKKKKK


Case 2 (FOLLOWING WHAT GOES OUT IN THE MANUAL)

public void onSelect$lb(){
		
		alert(myObject.name); //is null, because???

	}


NOT WORK ?????????????????????

BECAUSE ????????????????????????????????????????

zul
<window width="100%" height="100%" border="normal"
apply="ViewCtrl">
<listbox id="lb" selectedItem="@{ViewCtrl.myObject}" model="@<DispositivoViewCtrl.model>">
<listhead sizable="true">
<listheader label="Name" />
</listhead>
<listitem self="@{each=myObject}">
<listcell label="@{myObject.name}" />
</listitem>
</listbox>
</window>


zk 5.0.5(opssrc)

link publish delete flag offensive edit

answered 2011-02-09 09:35:16 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-09 09:41:52 +0800

Does this run ??
model="@<DispositivoViewCtrl.model>">


model="@{DispositivoViewCtrl.model}"

PS: Please have a look on Roberts Sample page here and do it like the sample (6).

link publish delete flag offensive edit

answered 2011-02-09 16:24:35 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-09 16:26:29 +0800

model="@<Ctrl.modelo>" ??????? why not {}

It's hard to try to translate your lines :-)

xcom, please read the well commented comments in Roberts sample and build it exactly like the sample especially the doAfterCompose() method.

link publish delete flag offensive edit

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

xcom gravatar image xcom
564 3

updated 2011-02-09 17:33:41 +0800

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

CODE_ONE=Ctrl.modelo //IN MANUAL NOT WOKR
CODE_two=$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

link publish delete flag offensive edit

answered 2011-02-10 08:33:54 +0800

xcom gravatar image xcom
564 3

I have an example without connecting to the database and it worked, now I will be an example but using spring and the database I hope it works .. then tell you how I was

link publish delete flag offensive edit

answered 2011-02-10 10:45:42 +0800

xcom gravatar image xcom
564 3

THANKS FINALLY WORKS AND FLY

A PAGE A LISTBOX VARIOUS MODELS

THANK YOU, IS A WONDERFUL ZK FRAMEWORK

link publish delete flag offensive edit

answered 2011-02-11 18:24:00 +0800

xcom gravatar image xcom
564 3

SOLVED THANKS

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-02-08 17:57:17 +0800

Seen: 1,853 times

Last updated: Feb 11 '11

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