Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:00:12+00:00 2026-06-06T15:00:12+00:00

If I have 2 .zul, one has a listbox, and another is the modal

  • 0

If I have 2 .zul, one has a listbox, and another is the modal window. can they use the same controller? I just can’t get it work.

the question basically resume at, do I have to use apply="myController" in both .zul?
if I do that, I get nullpointerException at myList, because I think zk is instantiating 2 controller objects, and the modal doesn’t exist myList. but If I don’t apply the controller at modal.zul, nothing happens when I press buttons.

how can I make 2 .zul use same instance of controller?

mail.zul

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
    <hlayout>
    <div id="winDiv" apply="com.company.controller.ProductController">
        <vbox>
            <listbox id="myList" width="690px" height="300px" >
                <listhead>
                    <listheader hflex="min" label="id" sort="auto(id)" />
                    <listheader hflex="2" label="name" sort="auto(name)" />
                    <listheader hflex="4" label="description" sort="auto(description)" />
                                        <listheader hflex="min" label="opcion"/>
                                </listhead>
            </listbox>
        </vbox>
    </div>
            <button label="new" id="new"/>
        </hlayout>
</zk>

the modal.zul

<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="modalProductType" title="Nuevo tipo de producto" border="normal" width="420px"
    closable="true" position="center,center" **apply="com.company.controller.ProductController"**>

    <grid>
        <columns>
                <column hflex="1"/>
                <column hflex="2"/>
        </columns>
        <rows>
                <row>
                    Clave:
                     <textbox hflex="1" value="@{product.id}" readonly="true"/>
                </row>
                <row>
                    Nombre:
                     <textbox id="txtname" value="@{product.name}" hflex="1" tabindex="1" />
                </row>
                <row>
                     Description:
                      <textbox value="@{product.description}" rows="5" hflex="1" tabindex="2" />
                </row>
                <row>
                    <cell colspan="2" style="text-align:center">
                        <hlayout>
                            <button width="100px" id="save" label="Aceptar"/>
                            <button width="100px" label="close"/>
                        </hlayout>
                   </cell>
                </row>
        </rows>
    </grid>
</window>

ProductController.java

public class ProductTypeController extends SelectorComposer {
@WiredVariable
    private ProductTypeService productTypeService;

@Wire
    private Listbox myList;

//methods...

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:00:13+00:00Added an answer on June 6, 2026 at 3:00 pm

    This is NOT recommended

    1. To avoid concurrency issues (Refer here) For eg. if same controller instance is applied to multiple views, the wired components will point to the last view causing erratic behavior of UI. It is easier to just use different instances instead of coding for concurrency issues and making controller thread safe.
    2. To avoid memory leak. For eg. if same controller instance is applied to two completely different views and components from both views are wired in it, then if one of the view is not being used its components wired will still not be released causing memory leak.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a really weird one here. The app has two targets, just to be
I can't reach component by id in the included .zul page. I have one
Have one Doubt In MVC Architecture we can able to pass data from Controller
everyone, I have faced one problem: The ZUL code: <window title=Hello World!! id=winMain border=none
Have deployed numerous report parts which reference the same view however one of them
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
Have a simple form that has a PictureBox in one location. I want to
I have a zul wich has two dependent combos. When an item of the
Have a question about calling one prototype function in another prototype function. for instance
Have an app that can use tts to read text messages. It can also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.