0

how to invoke redereritem

asked 2011-08-02 09:56:13 +0800

bhushan2169 gravatar image bhushan2169
138

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.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-08-03 09:03:47 +0800

marcelodecampos gravatar image marcelodecampos
183

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!
		}
	}
	
}

link publish delete flag offensive edit

answered 2011-08-03 23:51:50 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

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.

http://books.zkoss.org/wiki/ZK_Essentials/Displaying_information_using_the_Listbox/Using_a_ListModel_and_ListitemRenderer

link publish delete flag offensive edit

answered 2011-08-23 07:25:07 +0800

bhushan2169 gravatar image bhushan2169
138

thanku for your help

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-08-02 09:56:13 +0800

Seen: 391 times

Last updated: Aug 23 '11

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