-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have the following code:
<combobox id="pfcCombo2" readonly="true" width="270px"
model="@load(pjvm.pfcList)"
selectedItem="@bind(pjvm.selectedPfcItem)"
onSelect="@command('onSelectPfcCombo')"
disabled="@load(not pjvm.pfcComboEnabled)">
<template name="model" var="pfc">
<comboitem label="@load(pfc.pfc_desc)" value="@load(pfc.pfc_code)"></comboitem>
</template>
</combobox>
Works fine but when I try to change the content of the list:
PfcCode p = new PfcCode();
setPfcList(Arrays.asList(p));
setSelectedPfcItem(p); <-- throws exception:
SEVERE: >>org.zkoss.zk.ui.UiException: model of the databind combobox <Combobox vCGMb0#pfcCombo2> must be an instanceof of org.zkoss.zkplus.databind.B
indingListModel.[PfcCode{pfc_code=B10, pfc_desc=Radiator, market_code=null, prod_cat_code=null, service_type_code=null}]
Why ? ?
Are you using Bind Composer in Your ZUL file or not?
<window width="100%" height="100%" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.web.viewmodel.TaskListViewModel')">
Hi Tisaksen,
Can u please post a Demo Code here? Then I will check what you are trying to do i also Used ComboBox But did not get no any such exception
thanks
Here is demo code. the ZK version used is 6.01.
To reproduce problem, load demo.zul and select and item, then click on "Change entries!" and you will see the exception.
If you reload the page, then just click "Change entries!" without doing a selection first, then it works as expected (2 new items in combobox instead of original data)
demo.zul:
<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk xmlns="http://www.zkoss.org/2005/zul"
xmlns:h="http://www.w3.org/1999/xhtml"
>
<div id="theGrid"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('no.toyota.etmadmin.etmadminWeb.DemoViewModel')"
>
<combobox readonly="true" model="@bind(vm.demoList)" selectedItem="@bind(vm.selectedItem)">
<template name="model" var="s">
<comboitem label="@load(s)"/>
</template>
</combobox>
<button onClick="@command('changeEntries')" label="Change entries!"/>
</div>
</zk>
DemoViewModel.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package no.toyota.etmadmin.etmadminWeb;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
/**
*
* @author tisaksen
*/
public class DemoViewModel
{
private Logger log = Logger.getLogger(DemoViewModel.class);
private List<String> demoList;
private String selectedItem;
public DemoViewModel()
{
}
@Init
public void init() {
setDemoList(getAllDemos());
}
public void setDemoList(List<String> demoList) {
this.demoList = demoList;
}
public List<String> getDemoList() {
return demoList;
}
public List<String> getAllDemos() {
return Arrays.asList("A","B","C","D","E","F","G");
}
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
@Command
@NotifyChange("demoList")
public void changeEntries()
{
setDemoList(Arrays.asList("Foo","Bar"));
}
}
I found the problem, I tried to instansiate an instance from zkplus AnnotateBinderInit. Line 2 in demo.zul.
This created an instance from 5.x zplus package when I should be using 6.x org.zkoss.bind stuff, so I simply removed line 2 and it all works as expected.
Easy fix, hard to find ;)
Now I'm having another problem setting the selected item gives me out of bounds exception but at least I'm on step further.
Hi Tisaksen,
Your code is already given me Out Of Bound Exception .When I tried to run Your Code.Let me try some other code and will update you.
Hi Tisaksen,
Please go to the CLick Here and try Download and run the application.It will Work fine But When you will copy-paste same Code in Your Application it will not work .May this is a Jar Issue Please update jars your code Definitely work.I Did lots of POC on your code and other codes.If you have any concern please let me know
Thanks
I Tested Your Code with ZK6.0.2 and it worked fine So I am Sure If You will update your jars ,your code will work fine.
Thanks
sjoshi, thank you very much for your help.
It was a jar issue indeed! I had just upgraded from 5.x to 6.0.2 when I discovered the error. Now I have cleaned up jar files and everything is working just fine :-) Joy!
Asked: 2012-08-22 07:22:38 +0800
Seen: 254 times
Last updated: Aug 27 '12