0

"not unique in the id space" error caused by opening same page from 2 different tab zul files

asked 2011-07-13 00:02:43 +0800

pjiang gravatar image pjiang
46 2

updated 2011-07-13 00:05:55 +0800

Let me try to describe my problem clearly:

1. I have a panel.zul which includes 2 tab panel zul files. They are tab1.zul and tab2.zul

2. In tab1.zul, there is a button called button1; in tab2.zul, there is a button2.

3. when user clicks button1 or button2, same one zul file is opened as a new window. The code is like following:

tab1.zul
<window apply=”MainController”>
<button label=”open manage console”
onClick=”controller.openConsole()”
/>
</window>

Tab2.zul
<window apply=”MainController”>
<button label=” open manage console”
onClick=”controller.openConsole()”
/>
</window>

MainController.java
Public void openConsole(){
Map args = new HashMap();
Window w = (Window)Execution.getCurrent().createComponent(“newConsole.zul”, null, args);

}

newConsole.zul
<window id=”newConsole” apply=”newConsoleController.java”>
<!--Doing some very simple stuff ->
<button onclick="controller.doSomething()" />
</window>


My problem is: when I click button1, everything is fine; then I go to tab2 and click button2, the “Not unique in ID space of <windowId>” shows up…

What I’ve tried to solve the issue:

1. I make sure that before I go to tab2 and click button2, the new window created by clicking button1 is closed. I explicitly called window1.detach()

2. some suggestion says if we do not give ID to window, we won’t have the issue. It sounds reasonable. But I can’t do it. Because when user click the button in newConsole.zul, I need to do something and then close it. If I do not have a window ID, how can I close the window.

3. I search the error in ZK forum, some people recommend using a parent Component when I open the newConsole.zul. I tried. It does not fix the problem.


Anybody can help? It should be a very common situation that 2 buttons in 2 panel tab files open same page and initialize same controller……Do you all get this error?

Please help. Thank You!!!

Paula

delete flag offensive retag edit

4 Replies

Sort by » oldest newest

answered 2011-07-13 00:54:21 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

updated 2011-07-13 00:55:48 +0800

Let's discussed the reason first.


For one "IdSpace" , it can't have duplicated ID , since that will make the Id be ambiguous.

The code only show up the window , but I am not sure where you place the window ,
I mean , who will be the parent of the window.

The reasonable solution is placed the two window in different IdSpace, or remove the window id.


For example , create a IDSpaceDiv to handle this .
(or use another window to wrap it ,since currently only the window/include/HtmlMacroComponent implements IDSpace.)


---test/IDSpaceDiv.java---

package test;
public class IDSpaceDiv extends Div implements IdSpace{ }

-------------------------

Then modify your original code.

newConsole.zul 
<div use="test.IDSpaceDiv" >   <!-- here's the key point , we wrap the window with a IDSpace -->
    <window id=”newConsole” apply=”newConsoleController.java”> 
       <!--Doing some very simple stuff -> 
    <button onclick="controller.doSomething()" /> 
    </window> 
</div>


it's seldom for the showing up more then one window for each click , usually only showing one in same time,
in that case , popup or manually detach is good enough in that case.

Or another common use case is that each tab contains one window but using different name to handle this .

link publish delete flag offensive edit

answered 2011-07-13 00:57:19 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

More reference about the IdSpace

http://books.zkoss.org/wiki/ZK_Developer's_Reference/UI_Composing/ID_Space

link publish delete flag offensive edit

answered 2011-07-13 01:21:26 +0800

pjiang gravatar image pjiang
46 2

To answer your question:

Both of the window created by clicking button1 and button2 are opened on top of current window where I have the panel tab zul files. It means the 2 windows not only has same ID, also has same parent component. It might be the reason that adding parent component does not fix the problem.

for your solution, there is one thing I do not understand. My thought is, no matter what IDSpaceDiv we add outside the window on newConsole.zul, it won't make any difference. Because the 2 buttons will always open same newConsole.zul file and these 2 window will again end up with same IDSpace.

Sorry I won't be able to test your solution till tomorrow morning. I am just trying to understand it in theory.

link publish delete flag offensive edit

answered 2011-07-13 01:42:10 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

updated 2011-07-13 01:43:03 +0800

I guess I didn't explain it well.


For my solution , I wrap a IDSpace in newConsole.zul ,
so now your description will change from "two window in same parent" to "two IdSpace div(which contains the window) in same parent",

that means when you try to access the window , it's under a unique IdSpace , so the issue is not bothering you anymore.


Or if you need more control that you didn't mentioned which will break this use case ,
then we could discuss more details with you use case.

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: 2011-07-13 00:02:43 +0800

Seen: 515 times

Last updated: Jul 13 '11

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