0

SimpleListModel, Combobox + Databinding

asked 2008-04-30 20:29:22 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4937715

By: gsh_

I've been trying to get an autocomplete combobox to work properly, without success.

I started with the smalltalk "ListModel and Databinding Enhanced Combobox" at http://www.zkoss.org/smalltalks/comboboxEnhancement/. I am trying to combine the first example with the second. My problem is that I need databinding, but I can't load the entire list of over 5000 employees up front because it slows down the browser too much.

Here's a basic example of what I'm trying to do (using as much of the example code at that smalltalk as possible):

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk xmlns="http://www.zkoss.org/2005/zul">
<zscript>
public class Order {
private String _orderName;
private String _orderNumber;
public void setOrderName(String o) {
_orderName = o;
}
public String getOrderName() {
return _orderName;
}
public void setOrderNumber(String n) {
_orderNumber = n;
}
public String getOrderNumber() {
return _orderNumber;
}
}
int count = 30;
List orders = new LinkedList();

for(int j= 0; j < count; ++j) {
Order o = new Order();
o.setOrderName("OrderName - " + j );
o.setOrderNumber("OrderNumber - " + j);
orders.add(o);
}

ListModel orderlist = new SimpleListModel(orders);
//selected = orders.get(0);
</zscript>

<window width="500px">
<combobox model="${orderlist}" selectedItem="@{selected}"
value="@{selected.orderName}">
<comboitem self="@{each=order}" label="@{order.orderName}"
value="@{order.orderNumber}"/>
</combobox>
<grid>
<auxhead>
<auxheader align="center" colspan="2">Order Information</auxheader>
</auxhead>
<columns>
<column align="center" width="200px" label="Item"/>
<column align="center" width="200px" label="Value"/>
</columns>
<rows>
<row>OrderNumber: <label value="@{selected.orderNumber}"/></row>
<row>OrderName: <label value="@{selected.orderName}"/></row>
</rows>
</grid>
</window>
</zk>

The problem is that when I select an item that isn't one of the first 10, I get the data bound for the wrong item--I only get one of the first 10 results displayed. I am also getting this pesky error message every now and then that
says: "model of the databind combobox <Combobox z_i1_2> must be an instanceof of org.zkoss.zkplus.databind.BindingListModel.org.zkoss.zul.SimpleListModel@1d51
122.

Any help or advice would be greatly appreciated.

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2008-05-01 12:50:42 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4938808

By: henrichen

Try using ZK version 3.0.5 and change

ListModel orderlist = new SimpleListModel(orders);

to

ListModel orderlist = new BindingListModelList(orders, true);

/henri


link publish delete flag offensive edit

answered 2008-05-04 13:56:51 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4944124

By: frankiec

I have a list box with model that I want the listcells to update based on the asynchronous changing of the backing bean:

Here is snippet from Zul
========================
<label value="List of Jobs and their status"/>
<space/>
<listbox id="jslist"
checkmark="true"
multiple="true"
mold="paging"
pageSize="7"
fixedLayout="true"
pagingPosition="top"
width="750px"
model="@{WDJobMonitor.jobs}"
rows="7">
<listhead>
<listheader label="Job Name"/>
<listheader label="Created"/>
<listheader label="Started"/>
<listheader label="Completed"/>
<listheader label="Status"/>
</listhead>
<listitem self="@{each='jobs'}" value="@{jobs}">
<listcell label="@{jobs.jobName}"/>
<listcell label="@{jobs.createdDate}"/>
<listcell label="@{jobs.startDate}"/>
<listcell label="@{jobs.endDate}"/>
<listcell label="@{jobs.jobStateString}"/>
</listitem>
</listbox>

The jobs run in other threads, but the job itself is observable.

Any help?
Thanks
Frank

link publish delete flag offensive edit

answered 2008-05-05 03:27:38 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4944985

By: henrichen

You have to provide a timer to periodically check if the Jobs has been updated in onTimer. Then call

binder.loadAttribute(jslist, "model"); //have DataBinder to load the new model into the Listbox.

see

http://www.zkoss.org/javadoc/3.0.4/zkplus/org/zkoss/zkplus/databind/DataBinder.h
tml#loadAttribute(org.zkoss.zk.ui.Component,%20java.lang.String)

for details.

---
If you are familiar with server push, you can also choose calling binder.loadAttribute(jslist, "model") there.


/henri

link publish delete flag offensive edit

answered 2008-05-05 10:57:12 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4945588

By: frankiec

In attempting to user server push, I get the following error:

Cause: Expects java.util.Set, java.util.List, java.util.Map, Object[], Enum Class, or BindingListModel only. class org.zkoss.zkex.zul.SimpleListModelSharer$ProxyModel
org.zkoss.zk.ui.UiException: Expects java.util.Set, java.util.List, java.util.Map, Object[], Enum Class, or BindingListModel only. class org.zkoss.zkex.zul.SimpleListModelSharer$ProxyModel
at org.zkoss.zkplus.databind.ListModelConverter.coerceToUi(ListModelConverter.j
ava:56)
at org.zkoss.zkplus.databind.Binding.myLoadAttribute(Binding.java:251)
at org.zkoss.zkplus.databind.Binding.loadAttribute(Binding.java:234)
at org.zkoss.zkplus.databind.DataBinder.loadAttrs(DataBinder.java:467)
at org.zkoss.zkplus.databind.DataBinder.loadComponent(DataBinder.java:410)
at org.zkoss.zkplus.databind.DataBinder.loadAll(DataBinder.java:443)
...

link publish delete flag offensive edit

answered 2008-05-06 23:11:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4949210

By: frankiec

I'm using 3.04 BTW

link publish delete flag offensive edit

answered 2008-05-07 01:22:30 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4949335

By: waterbottle


Did you binding to a SimpleListModelSharer$ProxyModel??

SimpleListModelSharer$ProxyModel is a inner proxy model which implements ListModel You must access ProxyModel is pure ListModel way(it can only be operate by SimpleListModelSharer) and DataBinder don't know it and have now way to write it.

SimpleListModelSharer use operation queue(add data, remove data) to share data to different ProxyModel, but the data in each ProxyModel has different instance.
(http://www.zkoss.org/smalltalks/listmodelsharer/)

I think in current design of SimpleListModelSharer, it could not work with DataBinder.

Maybe you should post a feature request.

/Dennis



link publish delete flag offensive edit

answered 2008-05-07 01:34:05 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4949355

By: frankiec

Dennis,

Here is the code in the controller:
public void doBeforeComposeChildren(Component arg0) throws Exception
{
super.doBeforeComposeChildren(arg0);
wnd = (Window)arg0;

wnd.setVariable("_wdJobStubs",jobList,true);


wnd.getDesktop().enableServerPush(true);
lml = new ListModelList(JobMonitor.getJobMonitor().getJobs(),true);
slms = new SimpleListModelSharer(lml);
wnd.setVariable("_wdStats", slms,true);

}


link publish delete flag offensive edit

answered 2008-05-07 04:38:31 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4949527

By: waterbottle

Frank,

I can not catch point by above partial code. (who use _wdStats and
_wdJobStubs?)

Do you just want to use SimpleListModelSharer to help you handle asynchronized update and ServerPush?
As I described , SimpleListModelSharer can not work with DataBinder.
and DataBinder don't know how to handle ServerPush too.

My suggestion is, you don't need to use SimpleListModelSharer and you must handle Server Push you-self.
Before calling binder.loadAttribute , you must active desktop. After calling, then deactive desktop.
here is example : http://www.zkoss.org/smalltalks/serverpush/

/Dennis


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: 2008-04-30 20:29:22 +0800

Seen: 2,700 times

Last updated: May 07 '08

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