-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>
@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 }
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
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...
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.
Asked: 2012-07-11 22:57:48 +0800
Seen: 257 times
Last updated: Jul 14 '12