-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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)); } }
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.
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
Hi SimonPai,
Can we do this model on Combobox???
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
Asked: 2010-09-21 00:39:38 +0800
Seen: 1,377 times
Last updated: Mar 03 '11