-
FEATURED COMPONENTS
First time here? Check out the FAQ!
My code was working using ZK 5.0.2 FL.
But using ZK 5.0.4 and 5.0.5 FL it is not working.
Is this an bug?
Broken code
private void showForm(Menuitem menuitem) { if (!tabboxCenter.hasFellow(menuitem.getId())) { Tab tab = new Tab(); tab.setId(menuitem.getId()); tab.setLabel(menuitem.getLabel()); tab.setImage(menuitem.getImage()); tab.setClosable(true); Tabpanel tabPanel = new Tabpanel(); tabPanel.appendChild(new Include(Labels.getLabel("form.folder") + StringUtils.capitalize(menuitem.getId()) + Labels.getLabel("form.extension"))); tabboxCenter.getTabs().appendChild(tab); tabboxCenter.getTabpanels().appendChild(tabPanel); tabboxCenter.setSelectedTab(tab); tabboxCenter.setSelectedPanel(tabPanel); } }
Bellow is the stack trace
6/Out/2010 23:02:44 org.zkoss.zk.ui.impl.UiEngineImpl handleError:1265 SEVERE: >>java.lang.ClassCastException: org.zkoss.zul.Tab cannot be cast to org.zkoss.zk.ui.util.Composer >> at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:410) >> at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:397) >> at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposers(ComponentInfo.java:365) >> at org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:352) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:679) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:673) >>...
CidadeForm.zul
<?page id="cidadePage" title="${c:l('organization.title')}" contentType="text/html;charset=UTF-8" style="height:100%"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?> <zk> <window id="cidadeForm" width="auto" height="auto" border="none" apply="${cidadeForm}"> List of Cities </window> </zk>
CidadeForm.java
import org.zkoss.zk.ui.util.GenericForwardComposer; public class CidadeForm extends GenericForwardComposer { private static final long serialVersionUID = 1L; public CidadeForm() { } }
To be more precisely
Tab tab = new Tab();
tab.setId(menuitem.getId()); // Contains for example id = cidadeForm
Tabpanel tabPanel = new Tabpanel();
tabPanel.appendChild(new Include(Labels.getLabel("form.folder") + StringUtils.capitalize(menuitem.getId()) + Labels.getLabel("form.extension"))); // Inserted childrens contains id = cidadeForm, so same as the tab being created.
It is really very simple to reproduce the code.
The error was not suggestive, to the really problem: ID was being duplicated
I found the bug.
The bug is at my code. Interesting is that it was working with using ZK 5.0.2 FL.
BTW, I found that the tab created was with same name of the inserted children inside include. So, when resolving apply I think ZK found 2 same IDs components...
Regards,
Change
tabPanel.appendChild(new Include(Labels.getLabel("form.folder") + StringUtils.capitalize(menuitem.getId()) + Labels.getLabel("form.extension")));
To
tabPanel.appendChild(xx);
Which proves definitive there is an bug with creating include/tab at runtime.
The following is the MainForm.zul. The include of CidadeForm.zul direct to the forms works, but using the code it is not working. More below I printed the difference between include directly and those made by code.
<?page id="mainPage" title="${c:l('organization.title')}" contentType="text/html;charset=UTF-8" style="height:100%"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?> <zk> <window id="mainForm" width="100%" height="100%" border="normal" apply="${mainForm}"> <!-- CSS e JAVASCRIPT --> <style id="theme" src="/css/sdc_default.css" /> <script src="/js/ssw.js" type="text/javascript" /> <borderlayout> <north size="3%" flex="true"> <hbox widths="100%"> <include src="${c:l('form.menu')}" /> <button id="logout" image="/img/sair.gif" label="${c:l('mainForm.sair')}" /> </hbox> </north> <center style="overflow-y:auto"> <tabbox id="tabboxCenter" height="100%"> <tabs> <tab id="home" label="${c:l('mainForm.inicial')}" closable="false"/> <tab id="city" label="city" closable="true"/> </tabs> <tabpanels> <tabpanel><include src="${c:l('form.welcome')}"/></tabpanel> <tabpanel><include id="xx" src="/form/CidadeForm.zul"/></tabpanel> </tabpanels> </tabbox> </center> <south size="3%" flex="true"> <div id="dvFooter"> <toolbar height="20px"> ${c:l('index.username')} <toolbarbutton label="@{usernamePasswordCredentials.username}" /> ${c:l('index.workstation')} <toolbarbutton label="@{usernamePasswordCredentials.workstation}" /> </toolbar> </div> </south> </borderlayout> </window> </zk>
11-Nov-2010 16:50:21 INFO [com.ssw.sdc.web.MenuForm] GOOD: org.zkoss.zul.Include@b10190[
_src=/form/CidadeForm.zul
_dynams=<null>
_mode=auto
_localized=false
_progressing=false
_afterComposed=true
_instantMode=true
_comment=false
_progressStatus=0
_auxinf=<null>
_zclass=<null>
_prolog=<null>
_auxinf=<null>
_id=xx
_uuid=bXGQv1
_auxinf=org.zkoss.zk.ui.AbstractComponent$AuxInfo@e51510
]
11-Nov-2010 16:50:21 INFO [com.ssw.sdc.web.MenuForm] BAD: org.zkoss.zul.Include@f92cc8[
_src=/form/CidadeForm.zul
_dynams=<null>
_mode=auto
_localized=false
_progressing=false
_afterComposed=false
_instantMode=true
_comment=false
_progressStatus=0
_auxinf=<null>
_zclass=<null>
_prolog=<null>
_auxinf=<null>
_id=
_uuid=<null>
_auxinf=org.zkoss.zk.ui.AbstractComponent$AuxInfo@eb3c84
]
Peter,
When I replace Include by Iframe it works.
When I try to use an Div wrapper then include it is not working
Div div = new Div(); div.appendChild(new Include("..."));
Let me try to create an very simple code to reproduce the issue and post this as critical bug.
<bean id="cidadeForm" class="com.ssw.sdc.web.CidadeForm" scope="prototype" />
So the definition of CidadeForm was showed. It extends GenericForwardComposer.
Since I need to migrate to ZK 5.0.5 due to vlayout and hlayout I will try workarounds.
Asked: 2010-10-06 16:13:17 +0800
Seen: 1,452 times
Last updated: Nov 11 '10