-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am trying to wire component but i cant, i am getting "null" when clicked the button.
Note: I tried "NotifyChenged" it worked, but i want to try wiring...
<window apply="org.zkoss.bind.BindComposer" viewModel="@bind(vm='com.DenCtrl')"> <label id="lbl"/> <button label="Show" id="btn"> </window>
public class DenCtrl extends GenericAnnotatedComposer { @Wire private Label lbl; @Listen("onClick = button[id='btn']") public void showMsg() { System.out.println("Label = "+lbl); //lbl.setValue("Button Pressed..."); }
A view model is a POJO handled by the data binder. It is not a composer. In other words, neither ZK loader nor the data binder will call the afterCompose method to wire the components. If you really want to wire, you have to invoke afterCompose by yourself. However, it is a bit 'anit-pattern', since the view model is supposed not to access the components directly (which is the job of data binder). If you still prefer to do so, make sure not to access components that are handled by the data binder (i.e., don't access components with @save, @load...)
Right now, it is not easy to get the view (the UI component). In the upcoming RC2 (targeting next week), you could do as follows.
import org.zkoss.zk.ui.select.Selectors; public class Foo { @Init public void init(BindContext bctx) { Selectors.wireVariables(bctx.getComponent(), this); //Selectors.wireEventListeners(bctx.getComponent(), this); //better not to wire listeners. rather, use command } }
Notice that it is better not to implement Composer, since the concept of afterCompose is somehow conflict with BindComposer.
Asked: 2011-11-22 07:33:24 +0800
Seen: 535 times
Last updated: Dec 01 '11