Zk enabled .zul page not wotk with main controller

I used a tab to create a tab. And each tab contains a different zul page. I have 1 controller applied to the main page.

If I add any action to the component on the included zul page, I cannot catch it in the controller class. If I applied the controller to my zul, then it will create a new instance of the controller class.

Here is my code.

<zk> <style src="/resources/css/default.css" /> <window id="Dealer" class="index" apply="com.i2i.prm.controller.IndexController" width="100%" height="100%"> <div class="content" > <tabbox id="tb" width="100%" forward="onSelect=onSelect"> <tabs id="tabs"> <tab id="info" label="INFO" /> <tab id="create" label="CREATE" /> <tab id="edit" label="EDIT" /> </tabs> <tabpanels> <tabpanel id="DealerInfo"> <include id="DealerInfoContent" src="View/Dealer/DealerInfo.zul" /> </tabpanel> <tabpanel id="DealerCreate"> <include id="DealerCreateContent" src="View/Dealer/DealerCreate.zul" /> </tabpanel> <tabpanel id="DealerEdit"> <include id="DealerEditContent" src="View/Dealer/DealerEdit.zul" /> </tabpanel> </tabpanels> </tabbox> </div> </window> </zk> 

And dealerEdit.zul

 <zk> <window title="Dealer Edit" > <grid width="100%" sizedByContent="true"> <columns> <column label="" /> </columns> <rows> <row > <label value="Name"></label> <textbox value="@{DealerController.user.name }"> </textbox> </row> <row> <label value="Surname"></label> <textbox value="@{DealerController.user.surname }" forward="onChange=onASD"> </textbox> </row> <row> <label value="Address"></label> <textbox value="@{DealerController.user.address }"> </textbox> </row> </rows> </grid> </window> </zk> 

This is my control class ( IndexController.java ):

 public class IndexController extends GenericForwardComposer { private User user = new User();; AnnotateDataBinder binder; Tabbox tb; @Override public void doAfterCompose(Component comp) throws Exception { // TODO Auto-generated method stub super.doAfterCompose(comp); comp.setAttribute(comp.getId() + "Controller", this); binder = new AnnotateDataBinder(comp); user.setName("Abdul"); user.setSurname("Rezzak"); user.setAddress("Giderken sağda"); binder.loadAll(); } public IndexController() { // TODO Auto-generated constructor stub } public void onDFG(ForwardEvent event){ System.out.println(this.hashCode()); } public void onASD(ForwardEvent event){ System.out.println(this.hashCode()); } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } 
+4
source share
1 answer
  • delete <window title="Dealer Edit" > from your included page (DealerEdit.zul), since it forms its own IdSpace. Remember to remove the closing tag </window> .
  • change the name of the onASD method to include your component identifier Include ie onASD$DealerEditContent . It seems that Include also forms its own IdSpace, and the forward event does not work in IdSpace

That should work.

UPDATE 1: I just confirmed that Include is a component of the IdSpace owner, as it implements the IdSpace interface, so this is the only workaround in your case.

UPDATE 2: I found another easier way to handle forwarding events in different IdSpace, which should use the Path component in the ZUML file to specify the target component. For example, in your case, you can specify the page identifier on the page main.zul

 <?page id="main" ?> 

and while redirecting to your included page, such as the DealerEdit.zul page

 <textbox forward="onChange=//main/Dealer.onASD" /> 

The rest of the code will remain the same.

Link: http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/Event_Handling/Event_Forwarding#Using_component_Path

+3
source

All Articles