-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
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'}" selectedItem="@{win$composer.current}">
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 {
public void onChange$standort_textbox() { //update.focus(); //if (box.getSelectedItem() != null) { //update database String test = standort_textbox.getValue(); System.out.println(test); 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!
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.
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}"> <listhead> <listheader label="id"></listheader> <listheader label="A"></listheader> <listheader label="B"></listheader> </listhead> <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> </listitem> </listbox> </window>
package Demo; import javax.persistence.*; @Entity @Table(name="Demo") public class Demo { private int id; private String a; private String b; public Demo() { } @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="id") public int getId() { return id; } @Column(name="A") public String getA() { return a; } @Column(name="B") 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() { HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction(); return HibernateUtil.currentSession(); } public void SaveOrUpdate(Demo demo, String a, String b) { Session sess = currentSession(); demo.setA(a); demo.setB(b); sess.saveOrUpdate(demo); } public void delete(Demo demo) { Session sess = currentSession(); sess.delete(demo); } 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() { System.out.println("------------------------------------------------"); System.out.println(textbox.getValue()); System.out.println("------------------------------------------------"); System.out.println(textbox.getText()); //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.
Hi,
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) { System.out.println("------------------------------------------------"); System.out.println(((Textbox)evt.getOrigin().getTarget()).getValue()); }
Asked: 2010-01-22 04:35:08 +0800
Seen: 758 times
Last updated: Jan 25 '10