4

In our project we use ZK for webpages. There is a combobox which has lists. When selected, it fetches data from a java object through onSelect, i have given the logic. when i select one there are 4 listboxes on that page to be filled with data according to the selection. when i select first time, no problem occurs.

But on second time i get an error pop-up like "Not Unique in the id space of Window" and showing the list box item id which have to be filled on select.

Can any one help out there?

Note: Though it shows this error i get the listboxes filled correctly according to the combo box selection. Still i cant stop this error occurring..

Sitansu
  • 3,225
  • 8
  • 34
  • 61
Vignesh
  • 121
  • 3
  • 10

2 Answers2

1

Your issue is a conflict of ids in ZK's id space.

A bit of background..

ZK generates ids for components at runtime, if you open up the DOM in the browser you'll see each component has some machine readable id.

However, you can also give components an id. This id does not go to the DOM but lets you reference the component in your application.

These two shouldn't be confused. The conflict you're experiencing is with the latter type of id; you are assigning a component an id in your Java code or in your ZUL file which, at runtime, is not unique.

The case you describe where it only happens the second time you click is a tell tale sign here. The content you are adding on the event has an id defined in it and you are not removing this content when you are done.

Consider the following example:

@Wire
private Window myWindow;

@Listen(Events.ON_CLICK + " = #myButton")
public void onMyButtonClicked() {
    Label myLabel = new Label("sean is cool");
    myLabel.setId("myLabel");
    myLabel.setParent(myWindow);
}

This will work the first time you click myButton, but will throw your error on the second click. That is because the second event tries to add myLabel to myWindow but there is already a myLabel there.

There are lots of ways to resolve this depending on what you are trying to do.
Have a look through the ZK documentation on ID Spaces for more.

Sean Connolly
  • 5,692
  • 7
  • 37
  • 74
0

I also faced the same error. My scenario is the same, only the widgets being used are different. Hence putting my workaround here.

I have put the following piece of code in the doBeforeCompose() method of the composer:

Component widgetWithId = page.getFellowIfAny("widgetWithId");
if (widgetWithId != null) {
    widgetWithId.detach();
}

Here widgetWithId is the component/widget, which is tried to be regenerated by the code, with the same Id and ZK is throwing error for it.

RAS
  • 8,100
  • 16
  • 64
  • 86