I'm trying to set the selectedItem
in two different combos included in a custom component. I have a Java class which send the parameters to the zul through a map of args (Map<String,Object>)
.
In this map I send 2 ListModelList and 2 Objects (ListModelList<Object1> list1
, ListModelList<Object2> list2, Object1 o1, Object2 o2)
. The lists are supposed to populate the combos and the objects select the item.
selectedItem = ${arg.o1}
I got a conversion error, something like:can't convert
Object
... intoComboitem
Not a child:
<Comboitem null>
If I try to select the item by his index using "selectedIndex = ${arg.index1}"
(assuming index1 is the position of the object in his list), it return an out of bounds error.
If I try to select the item by onAfterRender="self.setSelectedIndex(${arg.index1})"
I got the error:
Cause: Sourced file: inline evaluation of:
self.setSelectedIndex(${arg.index1});
Attempt to access property on undefined variable or class name
If I use the ${arg.index1}
as value of a label it returns the expected value.
Your problem is that you put a ListModelList
into the combobox and selections goes on ComboItem
.
Selection of an item is now done through your model.
The solution is actually simple :
list1.setSelection(Arrays.asList(o1));
map.put("list1",list1);
list2.setSelection(Arrays.asList(o2));
map.put("list2",list2);
And send the map then.
If the list is correctly loaded into your listbox the selection will be correct.
Note : Custom components can have a controller to ;)