Problem with Databinding and Tetbox

asked 2010-01-22 04:35:08 +0800

TOtte gravatar image TOtte
93 2

I am vey new to zk, so pleace excuse me if there is an easy solution that I didn't find yet.

I have a window where I apply a controler and a listbox that is connected with my model:

<window id="win" title="Standorte" border="normal" apply="standort.StandortController">
 	<listbox id="box" multiple="true" rows="10" model="@{win$composer.alleStandorte, load-after='add.onClick, delete.onClick, update.onClick, standort_textbox.onChange'}"

The listbox contains a listitem. The object from the database is connected to this listitem and some cells have textboxes:

<listitem id="item" self="@{each='standort'}" value="@{standort}">
 		 	<listcell label="@{standort.cid}" />
 			<listcell label="@{standort.name}" />
 			<listcell label="@{standort.fullname}" />
 			<listcell><textbox id="standort_textbox" value="@{standort.standort}"/></listcell>

My controler extends the generic forward composer:

public class StandortController extends GenericForwardComposer {
and I have a method that handels the onChange event of the textbox specified above:
	public void onChange$standort_textbox() {
		//if (box.getSelectedItem() != null) {
			 //update database
			String test = standort_textbox.getValue();
			item = (Listitem) ((Listcell) standort_textbox.getParent()).getParent();
			Standort updateStandort = (Standort) item.getValue();
			//Standort updateStandort = (Standort) box.getSelectedItem().getValue();
			standortdao.saveOrUpdate(updateStandort, updateStandort.getSpace(), updateStandort.getStandort(), updateStandort.getHersteller());

As you can see in the comments there I tried two different methods to get the object from the listitem, but I can't get it to work.

I also tried to use onOK and onBlur, but that didn't help me either. The String test is always empty and I don't understnad why, it dirves me crazy right now.

Thanks for any help!

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-01-24 17:18:37 +0800

TOtte gravatar image TOtte
93 2

updated 2010-01-25 01:34:24 +0800

edit: I was wrong saying that it doesn't work even without the databinding. Without the Databinding I am able to access the content of the Textbox.

Other zk applications from this site that I looked into used the current item of the composer, but I think that it should also be possible to access a components value the way I am trying it.

link publish delete flag offensive edit

answered 2010-01-25 02:22:21 +0800

TOtte gravatar image TOtte
93 2

I created a small demo project to test acessing the textbox, but I still have the same problem.
I will post all the classes and the zul, so if there is an error someone might notice it.

<?page title="Auto Generated index.zul"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window id="win" title="Demo" border="normal" width="200px" apply="Demo.DemoController">
	<listbox id="box" model="@{win$composer.all}">
			<listheader label="id"></listheader>
			<listheader label="A"></listheader>
			<listheader label="B"></listheader>
		<listitem id="item" self="@{each='demo'}" value="@{demo}">
			<listcell label="@{demo.id}"></listcell>
			<listcell><textbox id="textbox" value="@{demo.A}"></textbox></listcell>
			<listcell label="@{demo.B}"></listcell>

package Demo;
import javax.persistence.*;

public class Demo {
	private int id;
	private String a;
	private String b;
	public Demo() {
	public int getId() {
		return id;
	public String getA() {
		return a;
	public String getB() {
		return b;
	public void setId(int id) {
		this.id = id;
	public void setA(String a) {
		this.a = a;
		b = a + " hallo";
	public void setB(String b) {
		this.b = b;


package Demo;
import java.util.List;
import org.zkoss.zkplus.hibernate.HibernateUtil;
import org.hibernate.Session;

public class DemoDAO {
	Session currentSession() {
		return HibernateUtil.currentSession();
	public void SaveOrUpdate(Demo demo, String a, String b)
		Session sess = currentSession();
	public void delete(Demo demo) {
		Session sess = currentSession();
	public Demo findById(int id) {
		Session sess = currentSession();
		return (Demo) sess.load(Demo.class, id);
	public List findAll() {
		Session sess = currentSession();
		return sess.createQuery("from Demo").list();


package Demo;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Window;
import org.zkoss.zul.Textbox;

import java.util.List;

public class DemoController extends GenericForwardComposer{
	Window win;
	Textbox textbox;
	Listitem item;
	DemoDAO demoDAO = new DemoDAO();
	public List all() {
		return demoDAO.findAll();
	public void onBlur$textbox() {
		//item = (Listitem) textbox.getParent().getParent();
		//Demo updateDemo = (Demo) item.getValue();
		//demoDAO.SaveOrUpdate(updateDemo, updateDemo.getA(), updateDemo.getB());


So I am not really doing much here, but I still can't get the text from the textbox. getValue() and getText() are both empty.

link publish delete flag offensive edit

answered 2010-01-25 03:32:08 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team


The template of Databinding is created by a for loop, so you can't use the id of "textbox" directly.
Please use this instead.

public void onBlur$textbox(ForwardEvent evt) {

link publish delete flag offensive edit

answered 2010-01-25 05:10:27 +0800

TOtte gravatar image TOtte
93 2

Thanks a lot jumperchen:) Now everything is working:)

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




Asked: 2010-01-22 04:35:08 +0800

Seen: 758 times

Last updated: Jan 25 '10

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