-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All,
I have a listbox which is bound to a model using annotations. And there is a small form which is linked to the "selectedItem" of the Listbox so that it shows the selected values:
================Code==========================
<window>
<a:bind model="books" selectedItem="selected"/>
<listbox rows="5" id="lstSample" model="@{win$composer.books}">
<listhead>
<listheader label="Title" width="100px"/>
<listheader label="Author" width="100px"/>
<listheader label="Details" width="100px"/>
</listhead>
<a:bind _var="book"/>
<listitem value="@{book}">
<a:bind label="book.title"/>
<listcell id="title"/>
<listcell>
<a:bind value="book.author"/>
<textbox id="author" inplace="true"/>
</listcell>
<a:bind label="book.details"/>
<listcell id="details"/>
</listitem>
</listbox>
<separator height="30px"/>
<!-- show the details of the selected item -->
<label value="show the details of the selected item (with databinding)"/>
<grid>
<rows>
<row>Title:
<a:bind value="selected.title"/>
<textbox/>
</row>
<row>Author:
<a:bind value="selected.author"/>
<textbox/>
</row>
</rows>
</grid>
<hbox>
<button id="getSelectedItem" label="Get Selected Item"/>
</hbox>
</window>
============ composer code ===================
Now, this works well except when I try to change the selected item programmatically. If I do a "setSelectedItem" on the Listbox from the composer, the newly selected item values are not reflected in the form below. The databinding doesn't work here. I tried doing a "binder.loadAll()" as well but it didn't work.
can someone help me on how to get the databinding to work here
Thanks,
Jai
Hi
I can't run your code, what is <a:bind ?
Do you have any other setting that didn't include here ?
Im sorry. <a:bind> are the binding representations. here is the complete code
<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?page zscriptLanguage="GroovyGrails"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.zkoss.org/2005/zk/annotation"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
<window>
<a:bind model="books" selectedItem="selected"/>
<listbox rows="5" id="lstSample" model="@{win$composer.books}">
<listhead>
<listheader label="Title" width="100px"/>
<listheader label="Author" width="100px"/>
<listheader label="Details" width="100px"/>
</listhead>
<a:bind _var="book"/>
<listitem value="@{book}">
<a:bind label="book.title"/>
<listcell id="title"/>
<listcell>
<a:bind value="book.author"/>
<textbox id="author" inplace="true"/>
</listcell>
<a:bind label="book.details"/>
<listcell id="details"/>
</listitem>
</listbox>
<separator height="30px"/>
<!-- show the details of the selected item -->
<label value="show the details of the selected item (with databinding)"/>
<grid>
<rows>
<row>Title:
<a:bind value="selected.title"/>
<textbox/>
</row>
<row>Author:
<a:bind value="selected.author"/>
<textbox/>
</row>
</rows>
</grid>
<hbox>
<button id="getSelectedItem" label="Get Selected Item"/>
</hbox>
</window>
</zk>
Hi
I modify your code as this, seems work fine, the lstbox do display the selected item
<?xml version="1.0" encoding="UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?page zscriptLanguage="GroovyGrails"?> <zk xmlns="http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.zkoss.org/2005/zk/annotation" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <zscript language="Java"><![CDATA[ class Book { String title; String author; String details; public Book (String title, String author, String details) { this.title = title; this.author = author; this.details = details; } public void setTitle(String title) { this.title = title; } public String getTitle() { return title; } public void setAuthor(String author) { this.author = author; } public String getAuthor() { return author; } public void setDetails(String details) { this.details = details; } public String getDetails() { return this.details; } } List books = new ArrayList(); books.add(new Book("a", "a_auth", "a_detail")); books.add(new Book("b", "b_auth", "b_detail")); books.add(new Book("c", "c_auth", "c_detail")); ]]></zscript> <window> <a:bind model="books" selectedItem="selected" /> <listbox rows="5" id="lstSample" model="@{books}"> <listhead> <listheader label="Title" width="100px" /> <listheader label="Author" width="100px" /> <listheader label="Details" width="100px" /> </listhead> <a:bind _var="book" /> <listitem value="@{book}"> <a:bind label="book.title" /> <listcell id="title" /> <listcell> <a:bind value="book.author" /> <textbox id="author" inplace="true" /> </listcell> <a:bind label="book.details" /> <listcell id="details" /> </listitem> </listbox> <separator height="30px" /> <!-- show the details of the selected item --> <label value="show the details of the selected item (with databinding)" /> <grid> <rows> <row> Title: <a:bind value="selected.title" /> <textbox /> </row> <row> Author: <a:bind value="selected.author" /> <textbox /> </row> </rows> </grid> <hbox> <button id="getSelectedItem" label="Get Selected Item" /> </hbox> </window> </zk>
hi kleptomac
i dont think triggering event is required.
binder.saveComponent(componentname) can do the work
Thanks
Jaikarthik Natarajan
I solve this problem using bandbox
<bandbox value="@load(pl.catSel)" mold="rounded">
<bandpopup>
<listbox id="lsbxCat" model="@load(pl.catModel)" selectedItem="@bind(pl.catSel)"/>
</bandpopup>
</bandbox>
Asked: 2010-06-15 06:30:44 +0800
Seen: 2,108 times
Last updated: May 15 '12