-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi,
I am developing an application where I have dynamically updated the listBox...now I wanted to retireve the labels of listcell when the user clicks on it...i tried to use self.getselecteditem().getLabel() but it is returning null.
also Its suggesting to invoke the redereritem. how to invoke it???
help me plz.
Hi, bhushan2169!
Is something like this??
this is a simple zul page
<?page title="Auto Generated index.zul"?> <window title="Hello World!!" border="normal" width="100%" height="100%" apply="com.test.simple.WindowController"> <label value="You are using: ${desktop.webApp.version}"/> <label value="Selected Item:" id="lblMsg"/> <listbox mold="paging" autopaging="true" vflex="true" id="list" > <listhead> <listheader label="Itens" sort="auto" > </listheader> </listhead> </listbox> </window>
package com.test.simple; import java.util.ArrayList; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Label; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Listbox; import org.zkoss.zul.Listcell; import org.zkoss.zul.Listitem; public class WindowController extends GenericForwardComposer { private static final long serialVersionUID = 1344018793022195316L; private Listbox list; private Label lblMsg; @Override public void doAfterCompose(Component comp) throws Exception { // TODO Auto-generated method stub super.doAfterCompose(comp); ArrayList<String> simpleListItens = new ArrayList<String> (); for ( int nIndex = 0; nIndex < 100; nIndex ++) { simpleListItens.add( "Item No.: " + nIndex ); } list.setModel( new ListModelList ( simpleListItens )); } public void onSelect$list () { Listitem item = list.getSelectedItem(); if ( item == null ) return; //THIS IS WHAT REALLY MATTERS!!!!!! Each line of listbox has a list of listcells (one or more) Object obj = item.getChildren().get(0); // get the first cell. if ( obj != null ) { Listcell cell = ( Listcell) obj; lblMsg.setValue( "Select Item: " + cell.getLabel() ); //get the label and show it! } } }
Hi ,
you could reference to this document.
There's a ListitemRenderer sample.
Also notice that usually we will setValue to the item , then you could use getSelectedItem().getValue() to get the value when onSelect.
thanku for your help
Asked: 2011-08-02 09:56:13 +0800
Seen: 391 times
Last updated: Aug 23 '11