0

Wiring problem after update...

asked 2012-07-11 22:57:48 +0800

kkurt gravatar image kkurt
300 1 2

Hi;
I have a working code with zk6 freshly(2012-06-04).
After upgraded to 2012-06-11,all wired components in controller are become NULL...
For ex. ZUL file:


<window border="none" apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('com.zk.IndexController')" >
<button id="bt1" onClick="@command('cmd1')" />
</window>


Contoller:

@Init
...
...
@Wire
Button bt1;

	 public void init(@ContextParam(ContextType.VIEW) Component view){
		Selectors.wireComponents(view, this, false);
}
@Command("cmd1")
public void command() {
System.out.println ("Button : "+bt1);         <========NULLL
}

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-07-12 04:05:27 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

If the code above is the same as your application, you miss argument of @wire.
The correct code is

@Wire("#bt1")  //bt1 is the id of component in zul you want wire

Notice: The design principle of MVVM pattern is that ViewModel should not have any reference to UI components.

reference: http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advance/Wire_Components

Regards,
Monty Pan

link publish delete flag offensive edit

answered 2012-07-12 04:58:37 +0800

kkurt gravatar image kkurt
300 1 2

Is not that the same thing?
Wire Button bt1 and Wire Button bt1("bt1").
I also tried that usage but it did not worked.
I know mvvm, but these codes are migrated from old version of zk. I am trying to be quick...

link publish delete flag offensive edit

answered 2012-07-13 06:16:31 +0800

paowang gravatar image paowang
140 6

If you read the reference Monty posted, "Usage Changed in 6.0.2" section tells us that usage has been changed.
The freshly version after 5-11 is 6.0.2 alpha, we should change code as above.

I write a example with freshly 07-12 version here:
index.zul

<zk>
	<window border="none" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('MyVM')">
		<button id="bt1" onClick="@command('cmd1')" label="button" />
	</window>
</zk>

MyVM.java


import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Button;

public class MyVM {

	@Wire
	Button bt1;

	@AfterCompose
	public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
		Selectors.wireComponents(view, this, false);
	}

	@Command("cmd1")
	public void command() {
		System.out.println("Button 1: " + bt1);
	}
}

Hope this helps.

link publish delete flag offensive edit

answered 2012-07-14 09:25:31 +0800

kkurt gravatar image kkurt
300 1 2

Thanks paowang, it worked.

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: 2012-07-11 22:57:48 +0800

Seen: 253 times

Last updated: Jul 14 '12

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