0

Change data in Combobox and setSelectedItem throws exception

asked 2012-08-22 07:22:38 +0800

tisaksen gravatar image tisaksen
44 5

updated 2012-08-22 07:23:12 +0800

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 ? ?

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2012-08-22 09:58:40 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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')">

link publish delete flag offensive edit

answered 2012-08-22 12:47:02 +0800

tisaksen gravatar image tisaksen
44 5

Yes I am using BindComposer

link publish delete flag offensive edit

answered 2012-08-22 16:13:33 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

link publish delete flag offensive edit

answered 2012-08-22 18:11:27 +0800

tisaksen gravatar image tisaksen
44 5

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"));
}
}

link publish delete flag offensive edit

answered 2012-08-23 07:19:16 +0800

tisaksen gravatar image tisaksen
44 5

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.

link publish delete flag offensive edit

answered 2012-08-23 09:02:07 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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.

link publish delete flag offensive edit

answered 2012-08-23 10:44:04 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

link publish delete flag offensive edit

answered 2012-08-23 10:55:43 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

link publish delete flag offensive edit

answered 2012-08-27 07:34:10 +0800

tisaksen gravatar image tisaksen
44 5

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!

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: 2012-08-22 07:22:38 +0800

Seen: 254 times

Last updated: Aug 27 '12

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