0

org.zkoss.zk.ui.UiException - You cannot access components belong to other desktop

asked 2009-08-07 17:17:36 +0800

rramirez gravatar image rramirez
6 1

Hi:

I have a index page like this....

<?xml version="1.0" encoding="UTF-8"?>
<zk>
<borderlayout id="index1">
<north size="115px">
<borderlayout>
<north size="90px">
</north>
<south size="25px">
<menubar id="menuIndex">
<menu label="Iniciar-Proceso" src="/img/computer1_16x16.gif">
<menupopup>
<menuitem label="ADD-ET" src="/img/computer2_16x16.gif" onClick="cargar.src = "equipoTecnologico.zul"" />
<menuseparator />
<menuitem label="ADD-Rol" src="/img/group.gif" onClick="cargar.src = "rol.zul""/>
<menuseparator />
<menuitem label="ADD-Componente" src="/img/computer2_16x16.gif" onClick="cargar.src = "View-Componente.zul""/>
<menuseparator />
<menuitem label="ADD-Dato" src="/img/computer2_16x16.gif" onClick="cargar.src = "View-Dato.zul""/>
<menuseparator />
<menuitem label="ADD-Función" src="/img/computer2_16x16.gif" onClick="cargar.src = "View-Funcion.zul""/>
</menupopup>
</menu>
</menubar>
</south>
</borderlayout>
</north>
<center>
<include id="cargar" src="" />
</center>
<south size="18px">
</south>
</borderlayout>
</zk>

When I load page "rol.zul" first time it work correctly, but if I load another one (anyone)
and try to load "rol.zul" again using the menu option I will get the following error:

org.zkoss.zk.ui.UiException - You cannot access components belong to other desktop

rol.zul is using a controller named rolviewcontroller that is created
on the SessionInit listener class.

Here is the code...

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./winRol"?>
<?page title="Roles" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winRol" width="100%" height="100%" apply="${sessionScope.rolController}">
<borderlayout>
<north size="0px">
</north>
<west size="640px" splittable="true" flex="true">
<borderlayout id="beanSummary"><!-- ******************** Extra Control ******************** -->
<north border="none" >
<div>
<hbox>
<button id="rolCreate" label="Nuevo" image="/img/file_16x16.gif"/>
<button id="rolUpdate" label="Editar" image="/img/edit_16x16.gif"/>
<button id="rolDelete" label="Eliminar" image="/img/delete_16x16.gif"/>
<separator/>
<separator/>
Filtro:
<combobox id="filt" >
<comboitem label=""/>
<comboitem label=""/>
</combobox>

</hbox>
<paging id="rolPaging"/>
</div>
</north>

<!-- ******************** List View of Table ******************** -->

<center border="none" flex="true">


<listbox id="listbRol" fixedLayout="true" multiple="true" checkmark="true" style="border:none"
mold="paging">

<!-- ******************** Generated By Bean Field Def ******************** -->

<listhead sizable="true">
<listheader id="descrip" label="Descripcion" />
</listhead>

<!-- ******************** Generated By Bean Field Def ******************** -->

<listitem>
</listitem>
</listbox>
</center>
</borderlayout>
</west>
<center>
<div id="rolDetail">
<!-- ******************** view mode ******************** -->
<div id="beanView" width="100%">
<grid width="100%" >
<columns>
<column align="right" width="90px"/>
<column align="left"/>
</columns>
<rows>
<row >Descripcion :<label id="lbDescRol" /></row>
</rows>
</grid>
<separator/>
</div>

<!-- ******************** edit mode ********************
<div id="rolEdit" >
<grid width="100%" fixedLayout="true">
<columns>
<column align="right" width="90px"/>
<column align="left"/>
</columns>
<rows>
<row>Descripcion :<textbox id="Descripcion" /></row>
</rows>
</grid>
<separator/>
<div align="right">
<hbox>
<button id="rolSave" label="Guardar" image="/img/save_16x16.gif"/>
<button id="rolCancel" label="Cancelar" image="/img/cancel.png"/>
</hbox>
</div>
</div> -->
</div>
</center>
</borderlayout>
</window>
</zk>

this is the class...

public class RolViewController extends ViewController
{
protected Listbox listbRol;
protected Combobox filt;
protected Button rolCreate, rolUpdate, rolDelete;
protected ListModelList listModelList;
protected Label lbDescRol;

@Override
public void doAfterCompose(Component window) throws Exception {
super.doAfterCompose(window);

baseListBean = new RolListBean("descRol");
baseListBean.setServiceLocator(Main.getServiceLocatorBean());
baseListBean.fillBeanList();

listModelList = new ListModelList();
listModelList.addAll(baseListBean.getBeanList());
listbRol.setModel(listModelList);
listbRol.setItemRenderer(this);

listbRol.addEventListener("onSelect", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
int index = listbRol.getSelectedIndex();

RolViewBean rolViewBean = (RolViewBean) listModelList.get(index);
lbDescRol.setValue(rolViewBean.getDescRol());
}

});

}

@Override
public void render(Listitem listItem, Object data) throws Exception {
RolViewBean rol = (RolViewBean ) data;
(new Listcell(rol.getDescRol())).setParent(listItem);
}

@Override
public void render(Comboitem arg0, Object arg1) throws Exception {
}

/**
}


this is the listener class...

public class CetSessionInit implements SessionInit {

@Override
public void init(Session session, Object request) throws Exception {
CompoViewController compoControler = new CompoViewController();
session.setAttribute("compoControler", compoControler);

RolViewController rolController = new RolViewController();
session.setAttribute("rolController", rolController);

return;
}
}

this is the zul.xml

<zk>
<listener>
<description>MyController Session Initialiser</description>
<listener-class>cet.controller.CetSessionInit</listener-class>
</listener>

</zk>

Did anyone knows what this happen and how can be avoid?
RolviewController is share controller (another zul page use it) so I need it to be a singleton.

Regards, Reynaldo.

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2009-08-07 23:46:23 +0800

jtoupin gravatar image jtoupin
156

updated 2009-08-07 23:46:42 +0800

You cannot share a controller. It has to be a different one for each page. This is probably what your problem is.

link publish delete flag offensive edit

answered 2009-08-10 17:50:37 +0800

rramirez gravatar image rramirez
6 1

updated 2009-08-10 17:58:07 +0800

Hi:

The share controller is not the problem, this class is shared by rol.zul and a popup window that shows when I press the "Nuevo" button, that part works fine but if I move to another page (with another controller) and try to go back using the menu option I get the error. Maybe is there a way to reload the same page in the desktop??

link publish delete flag offensive edit

answered 2010-09-30 16:50:36 +0800

Jahaziel gravatar image Jahaziel
3

I have the same problem rramirez. Do u have the solution?

link publish delete flag offensive edit

answered 2010-10-04 21:25:14 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Did you cache your component beyond the scope of a desktop? e.g. in session, in servelet, in application, or in VM static variable, ...

99% of such exception is caused by such operation.

link publish delete flag offensive edit

answered 2011-10-28 15:00:36 +0800

carpolva gravatar image carpolva
155 4

Hi!!.... I've solved my problem :D

I had my controller definition like the following:

<window id="win" width="1845px" apply="${sessionScope.myBean}">

and I changed it by:

        <zscript>
		<![CDATA[
			import com.domain.bean.MyBean;
			MyBean myBean = new MtBean();
		]]>
	</zscript>

	<window id="win" width="1845px" apply="${myBean}">

Because at session initialization

apply="${sessionScope.myBean}"
only one instance of myBean will be used during all the application lifetime, so when a user refresh the page (F5) a new desktop is created and conflicts with the previous created components (of that controller instance) thinking they belong to the previous desktop. Instead with the second way every time the page is reloaded a new desktop and a new controller are created.

link publish delete flag offensive edit

answered 2016-09-16 07:09:03 +0800

Ting gravatar image Ting
1

This error message you got is expected behavior. Basically, after you open the second tab in the same browser, a new desktop is created and the old desktop (first tab) is removed and all the view components it contains are made invalid. Therefore, when you go back to the first tab and click on something. This event will no longer belongs to the new desktop.

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: 2009-08-07 17:17:36 +0800

Seen: 2,103 times

Last updated: Sep 16 '16

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