0

org.zkoss.zul.Tab cannot be cast to org.zkoss.zk.ui.util.Composer

asked 2010-10-06 16:13:17 +0800

sousa1981 gravatar image sousa1981
573 4

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() {
	}


}

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2010-10-11 23:42:43 +0800

PeterKuo gravatar image PeterKuo
481 2

apply="${cidadeForm} looks for composer.
From your error message, it's most like ${cidadeForm} is resolved as a tab.
Can you confirm it and dig further?

link publish delete flag offensive edit

answered 2010-11-11 07:50:54 +0800

sousa1981 gravatar image sousa1981
573 4

updated 2010-11-11 07:56:07 +0800

<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.

link publish delete flag offensive edit

answered 2010-11-11 08:04:40 +0800

sousa1981 gravatar image sousa1981
573 4

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.

link publish delete flag offensive edit

answered 2010-11-11 08:54:42 +0800

sousa1981 gravatar image sousa1981
573 4

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: [email protected][
_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
[email protected]
]
11-Nov-2010 16:50:21 INFO [com.ssw.sdc.web.MenuForm] BAD: [email protected][
_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>
[email protected]
]

link publish delete flag offensive edit

answered 2010-11-11 08:57:54 +0800

sousa1981 gravatar image sousa1981
573 4

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.

link publish delete flag offensive edit

answered 2010-11-11 08:59:44 +0800

sousa1981 gravatar image sousa1981
573 4

You should check what is happens betweens _afterComposed=true ald _afterComposed=false

link publish delete flag offensive edit

answered 2010-11-11 09:09:14 +0800

sousa1981 gravatar image sousa1981
573 4

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,

link publish delete flag offensive edit

answered 2010-11-11 09:15:52 +0800

sousa1981 gravatar image sousa1981
573 4

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

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: 2010-10-06 16:13:17 +0800

Seen: 1,446 times

Last updated: Nov 11 '10

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