robertpic71
1275 1

I don't want create my model when the page is created. I should be created after a buttonclick. But the binder seems to be damaged after load a null model.

Here is my code:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="wnd"?>

<window id="wnd" width="100%" onCreate="onCreate()">
<zscript>
import org.zkforge.converters.JDBCBind;
JDBCBind jdbcBind;
BindingListModel model;
AnnotateDataBinder dataBinder;

void onCreate() {
jdbcBind = new JDBCBind("jdbc/h2", 0);
dataBinder = (AnnotateDataBinder) wnd.getVariable("binder", false);
}

model = jdbcBind.getAutoGrowSQL("select infoid, fileid, name from dept order by infoid", pager);
}
</zscript>
<caption label="AutoGrow, load on ButtonClick  - 1710 Records" />

<paging id="pager" pageSize="40" />
<listbox width="95%" fixedLayout="true" mold="paging"
model="@{model, load-when='none'}" paginal="${pager}"> <listhead sizable="true"> <listheader label="InfoId" width="35px" /> <listheader label="FileId" width="35px" /> <listheader label="Text" width="500px" /> </listhead> <listitem self="@{each=row}"> <listcell label="@{row.infoid}" /> <listcell label="@{row.fileid}" /> <listcell label="@{row.name}" /> </listitem> </listbox> </window> When i hit the loadbutton, i get the right data, but not in the same order. I logged my model and the UI gets the items in the right order. You can see this effect here. Load the page, hit the loadbutton and see the unsorted data, hit the loadbutton once more and you get the right order. I've tried to disable the loading-events with: model="@{model, load-when='none'}. But the value "none" seems only supported for save-when. Any ideas? /Robert BTW: my growingmodel works also nice with the Livelistbox, see here. Pretty cool for a webapplication. delete retag edit ## 5 Replies Sort by » oldest newest answered 2008-07-24 06:35:51 +0800 henrichen 3869 2 Robert, Since you will not bind data until click the button (calling load()), you can defer the creation of the Data Binder until onCreate(). 1. Take away the <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="wnd"?> What the init did is new a AnnotateDateBinder and call loadAll() when doAfterCompose(). Remove this line, there will be no AnnotatDataBinder and thus no loadAll(). in onCreate(), new your own AnnotateDataBinder.  void onCreate() { jdbcBind = new JDBCBind("jdbc/h2", 0); dataBinder = (AnnotateDataBinder) new AnnotateDatabinder(wnd, true); }  Check javadoc for details. I will check the strange behavior you described. /henri answered 2008-07-25 01:15:54 +0800 robertpic71 1275 1 Hello henri, thanks for the answer. Of course for this example i could move the DataBinder to the loadevent. But when i get annotated headerfields, i need the databinder while composingphase. Maybe a dummymodel could be a work-a-round. >> I will check the strange behavior you described. Here is a link to see and some code to test: BinderTest.zul <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="wnd"?> <window id="wnd" width="100%" onCreate="onCreate()"> <zscript> List entries = new ArrayList(); BindingListModel model; AnnotateDataBinder dataBinder; HashMap map; void onCreate() { dataBinder = (AnnotateDataBinder) wnd.getVariable("binder", false); } void load() { for(int j=0; j < 50; ++j) { HashMap fieldMap = new HashMap(3); fieldMap.put("infoid", j); fieldMap.put("fileid", "M" + j); fieldMap.put("name", "Name " + j); entries.add(fieldMap); } model = new BindingListModelList(entries, true); dataBinder.loadAll(); } </zscript> <caption label="First display is unsorted, why?" /> <button id="load" label="Load" onClick="load()" /> <paging id="pager" pageSize="40" /> <listbox width="95%" fixedLayout="true" mold="paging" model="@{model}" paginal="${pager}">
<listitem self="@{each=row}">
<listcell label="@{row.infoid}" />
<listcell label="@{row.fileid}" />
<listcell label="@{row.name}" />
</listitem>
</listbox>
</window>	

/Robert

BTW 1: nice pager-element in Version 3.5.0FL
BTW 2: nice new website

henrichen
3869 2

Robert,

You don't need Data Binder in composing phase. Annotation is a separate concept with Data Binder. That is, annotation is annotation, Data Binder is Data Binder. The relation between the two is that the Data Binder "happens to know" what these annotations associated with Component and attribute means and "do what it is told to do".

Actually, you can invent your own annotation "syntax set" and implement your own Data Binder or whatever other function manager. Annotation the mechanism is kind like some "meta data" or "tag" linked with the component and you can use them in some other way, not just for Data Binding.

henrichen
3869 2

Of course, in your real application, if other part of the page needs DataBinder to loadAll(), my previous suggestion would not work. Try providing an "empty" BindingListModelList first. Thanks for the test case. I will investigate this issue.

[hide preview]