-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all, in an MVC architecture I'm trying to add a component to the zul page in the java composer, and bind a value to that component.
Zul:
<?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?link rel="stylesheet" type="text/css" href="/css/BDGZKStyles.css"?> <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" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <div id="grid" apply="it.finmatica.bdg.composer.test.TestGridComposer"> <hlayout> <label value="in zul:"/> <textbox id="tbzul" value="@{grid$composer.s}" width="600px" forward="onChange=grid.onChange()"/> </hlayout> </div> </zk>
Composer:
@Override public void doAfterCompose(Component comp) { super.doAfterCompose(comp) binder = new AnnotateDataBinder(comp); final String beanId = "beanId" binder.bindBean(beanId, s); tb = new Textbox(); tb.setInplace(true); tb.addForward("onChange", "grid", "onChange"); binder.addBinding(tb, "value", "beanId"); grid.appendChild(tb); binder.loadAll() } public void onChange(ForwardEvent event){ System.out.println("tb in zul: " + tbzul.getValue()); System.out.println("tb in java: " + tb.getValue()); System.out.println("s: " +s ); binder.loadComponent(tb); binder.loadAll() } }
Ciao Stefano!
I'm not fully sure about what did you tried to achieve but... the following snippet is working:
public class TestComposer extends GenericForwardComposer { private AnnotateDataBinder binder; private Textbox tb1; private Textbox tb2; private Person person = new Person(); private Component container; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); binder = new AnnotateDataBinder(comp); //<textbox value="@{person.name}" hflex="1" forward="onChange=onMyChange" /> tb2 = new Textbox(); tb2.addForward("onChange", self, "onMyChange"); tb2.setHflex("1"); binder.addBinding(tb2, "value", "person.name"); container.appendChild(tb2); binder.bindBean("person", person); binder.loadAll(); } public void onMyChange(ForwardEvent event){ System.out.println("tb1: " + tb1.getValue()); System.out.println("tb2: " + tb2.getValue()); System.out.println("person's name: " + person.getName() ); binder.loadAll(); } }
zul file:
<?xml version="1.0" encoding="UTF-8"?> <zk> <div apply="demo.TestComposer" width="300px"> <vlayout id="container"> <textbox id="tb1" value="@{person.name}" hflex="1" forward="onChange=onMyChange" /> </vlayout> </div> </zk>
hope it helps!
Giovanni
Asked: 2012-11-26 15:37:53 +0800
Seen: 72 times
Last updated: Nov 27 '12