-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I'm trying to follow the steps in the development guide in order to programmatically instantiate a regular macro component. However it's beeing impossible for me to retrieve the macro component definition. I've tried the following in the online demo:
<?component name="newProduct" macroURI="/userguide/misc/includedMacro.zul"?> <zk> <hbox> <newProduct /> <newProduct title="Monitor" img="/img/item1.jpg" desc="The new HDMI monitor"/> <newProduct id='_p' title="Cell" img="/img/item2.jpg" desc="This is zPhone"/> <button label='Try and fectch "newProduct" component definition' onClick='alert( "" + page.getComponentDefinition("newProduct", false ) + " in page " + page );' /> <button label='What page do the newProduct instances belong to?' onClick='alert( _p.getDefinition().getName() + " in page " + _p.getPage() );' /> </hbox> </zk>
With kind regards
César Varona
Curiously enough, if I modify test.zul like this
<?xml version='1.0' encoding='UTF-8' ?> <?component name="macro" macroURI="/macro.zul"?> <window id='w'> <macro id='_justForTheSakeOfInstantiation' visible='false' /> <zscript> HtmlMacroComponent macro = ( HtmlMacroComponent ) _justForTheSakeOfInstantiation.getDefinition().newInstance( page, null ); macro.setParent( w ); macro.applyProperties(); macro.afterCompose(); </zscript> </window>
Hi Peter,
I tried it on the demo because I was being unable to get the macro component definition and wanted to put up a simple example. Since it failed the same way it did in my environment I supposed it was actually like that.
After reading your post I tried a simplified version and discovered you're right. After reflecting for a while about it I realised it was my loading the page with the <?component ?> directive via Executions.createComponents that made the difference. In other words, this works:
macro.zul
<label value='This is just a test' />
test.zul
<?xml version='1.0' encoding='UTF-8' ?> <?component name="macro" macroURI="/macro.zul"?> <window id='w'> <zscript> HtmlMacroComponent macro = ( HtmlMacroComponent ) page.getComponentDefinition( "macro", false ).newInstance( page, null ); macro.setParent( w ); macro.applyProperties(); macro.afterCompose(); </zscript> </window>
This however doesn't:
invoke_test.zul
<window title='Invokes test' id='itest'> <zscript>Executions.createComponents( "/test.zul", itest, null );</zscript> </window>
Do you think this is so for some good reason or it can be considered rather a bug?
With kind regards
César Varona
Asked: 2008-12-24 09:58:45 +0800
Seen: 242 times
Last updated: Dec 26 '08