ZK window not unique in ID space

烂漫一生 提交于 2019-12-05 16:26:55

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!