0

Wiring components in ZK 6

asked 2011-11-22 07:33:24 +0800

kkurt gravatar image kkurt
300 1 2

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>

and controller :

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...");
                      }



What is the problem?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-11-23 11:39:51 +0800

kkurt gravatar image kkurt
300 1 2

any idea?

link publish delete flag offensive edit

answered 2011-11-25 09:29:58 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

updated 2011-11-25 09:34:22 +0800

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...)

link publish delete flag offensive edit

answered 2011-11-28 07:17:13 +0800

kkurt gravatar image kkurt
300 1 2

Thanks, i understand. But if i want to wire, how can i do this. I mean where should i call afterCompose?
Can you give a little example ?

link publish delete flag offensive edit

answered 2011-12-01 10:57:57 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

updated 2011-12-02 01:10:51 +0800

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.

link publish delete flag offensive edit

answered 2011-12-01 12:40:26 +0800

kkurt gravatar image kkurt
300 1 2

Ok, thank you Tom.

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

Follow

RSS

Stats

Asked: 2011-11-22 07:33:24 +0800

Seen: 535 times

Last updated: Dec 01 '11

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