0

Refreshing Listbox Or Combobox

asked 2010-09-21 00:39:38 +0800

rohitwadke gravatar image rohitwadke
339 1 5

Hello All,

I am i have tried listbox and combobox but not able to find solution for my problem.

following are the problem i am facing
on form load i m loading my 1st combobox
1) on selection on item i m loading 2nd combobox
2) but if i try to change 1st combobox value result dont get refresh on 2nd combobox


Eg
in 1st combo i have animal, fish
in 2nd combo i have their respective names

if i select animal i get all name on animals but after selecting animal name,
if i select 1st combo and select fish then fish name dont show on 2nd combobox


i m using simplelist model


Please give me solution for this..

Thank you in Advance

Rohit

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2010-09-21 04:35:13 +0800

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

Sounds like cascade listboxs ?

Here is a easy example for cascade listbox.

testCascadeListbox.zul

<?page title="Test cascade list box" ?>
<zk>
	<window id="win" apply="test.TestCascadeListboxComposer">
		<label value="the first numbers" />
		<listbox id="first"  >
			<listhead>
				<listheader label="number" width="100px" />
			</listhead>
		</listbox>
		<label value="the second numbers" />
		<listbox id="second">
			<listhead>
				<listheader label="number" width="100px" />
			</listhead>
		</listbox>
	</window>
</zk>


test.TestCascadeListboxComposer

package test;

import java.util.ArrayList;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
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;
import org.zkoss.zul.ListitemRenderer;

public class TestCascadeListboxComposer extends GenericForwardComposer {

	Listbox first;

	Listbox second;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		ArrayList<Integer> firstlist = new ArrayList<Integer>();

		for (int i = 1; i <= 5; i++) {
			firstlist.add(Integer.valueOf(i));
		}

		first.setModel(new ListModelList(firstlist));

		/**
		 * here is for rendering listbox rows ,in this example , it's simple for
		 * one listcell with number string.
		 */
		first.setItemRenderer(new ListitemRenderer() {

			public void render(Listitem item, Object data) throws Exception {
				item.appendChild(new Listcell(data.toString()));
			}
		});
		second.setItemRenderer(new ListitemRenderer() {

			public void render(Listitem item, Object data) throws Exception {
				item.appendChild(new Listcell(data.toString()));
			}
		});
	}

	public void onSelect$first() {
		int number = (Integer) first.getModel().getElementAt(first.getSelectedIndex());
		ArrayList list = new ArrayList();

		for (int i = 1; i <= 5; i++) {
			list.add(number * i);
		}
		second.setModel(new ListModelList(list));
	}

}

link publish delete flag offensive edit

answered 2010-09-21 07:02:57 +0800

rohitwadke gravatar image rohitwadke
339 1 5

hey Thank you for your reply it was usefull but still there is one problem with selecting 1st element from first listbox...
u cannot select ur 1st item from first listbox.

link publish delete flag offensive edit

answered 2010-09-22 20:56:31 +0800

SimonPai gravatar image SimonPai
1696 1

Hi rohitwadke,

When clicking on the currently selected item in a listbox, the onSelect event will not be fired. You can fill the content of the second listbox in doAfterCompose(), as if the user has already select the first listitem of the first listbox.

Regards,
Simon

link publish delete flag offensive edit

answered 2010-09-28 00:45:38 +0800

rohitwadke gravatar image rohitwadke
339 1 5

Hi SimonPai,

Can we do this model on Combobox???

link publish delete flag offensive edit

answered 2010-09-30 21:01:15 +0800

SimonPai gravatar image SimonPai
1696 1

rohitwadke,

Supposedly the logic for Combobox is the same. Have you tried and met some challenge?

Regards,
Simon

link publish delete flag offensive edit

answered 2011-03-03 07:33:52 +0800

kvenu28 gravatar image kvenu28
6

I am unable to use cascading combo / List box for more than seven times in the same page.

Seven times changing same combo fails at eighth time.

Eight different combos linked aslo fails at eigth combo.

My usage is like this :

Origin Region -> Origin Country - >Origin Airport -> Origin Connecting Airport
Dest Region -> Dest Country - >Dest Airport -> Dest Connecting Airport

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: 2010-09-21 00:39:38 +0800

Seen: 1,377 times

Last updated: Mar 03 '11

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