Passing listbox id to modal in order to use it to a controller

asked 2019-05-29 18:42:46 +0800

GioZiak gravatar image GioZiak

updated 2019-05-30 11:45:04 +0800

cor3000 gravatar image cor3000
5250 2 7
ZK Team


I have a main.zul where i make a listbox with id "coursesEventsListboxProf".There i have a button that calls ModalDialogController (like the zk examples).In ModalDialogController i just do

Window window = (Window)Executions.createComponents( "professor_dialog.zul", null, null);



In professor_dialog.zul i just have a grid with 3 textboxes.There when the user fill out the textboxes, i have a button with id="subBtnmodal" and a controller called UserDataController from where i handle the values of textboxes. The thing is that i want to handle the listbox with the id "coursesEventsListboxProf" but i get NullPointerException (obviously) and i dont know how to "pass" it from main.zul. Thanks.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-05-30 10:55:08 +0800

hawk gravatar image hawk
2620 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2019-05-30 11:53:04 +0800

Looks like there are at least 2 controllers with parent-child relationship. You can get a component reference of a parent page in a child page, but this approach makes 2 controllers more coupling.

Fire an event

It's better to post an event among them, e.g.

parent page can add an event listener for a custom event: window.addEventListener("onInnerButtonClicked", e -> {update listbox})

when a user clicked subBtnmodal, you just post an event like: Events.postEvent(window," onInnerButtonClicked")

Please refer to Inter-Page_Communication

Pass ID

you can pass id with the last arguments like:

Window window = (Window)Executions.createComponents( "professor_dialog.zul", null, Collections.singletonMap("listbox", "coursesEventsListboxProf"));

In the controller of professor_dialog.zul, you can get passed id with Execution.getArg()

refer to javadoc

link publish delete flag offensive edit

answered 2019-05-30 12:13:03 +0800

cor3000 gravatar image cor3000
5250 2 7
ZK Team

updated 2019-05-30 12:34:50 +0800

an alternative to Pass ID is to pass the component instance directly:

Window window = (Window)Executions.createComponents( "professor_dialog.zul", null, Collections.singletonMap("listbox", coursesEventsListboxProf));

In the controller of professor_dialog.zul

Listbox lb = (Listbox)Execution.getArg("listbox");

Still if sufficient I'd prefer the event based approach.

link publish delete flag offensive edit
Your answer
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




Asked: 2019-05-29 18:42:46 +0800

Seen: 14 times

Last updated: May 30 '19

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