0

Unable to programmatically retrieve a regular macro component definition

asked 2008-12-24 09:58:45 +0800

cvarona gravatar image cvarona
554 1 6

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>
The newProduct instances actually belong to the current page, but it looks like the page is unaware of their component definitions. Must it actually be like that? Am I missing something? Any help would be much appreciated.

With kind regards

César Varona

delete flag offensive retag edit

3 Replies

Sort by » oldest newest

answered 2008-12-26 14:26:09 +0800

cvarona gravatar image cvarona
554 1 6

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

link publish delete flag offensive edit

answered 2008-12-24 13:43:46 +0800

cvarona gravatar image cvarona
554 1 6

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

link publish delete flag offensive edit

answered 2008-12-24 11:31:08 +0800

PeterKuo gravatar image PeterKuo
481 2

I think it's problem of online demo. Maybe it's security reason.
I tried it in local machine, it runs well.
It do alert "
[ComponentDefinition: newProduct] in page [Page z_94_0] "

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: 2008-12-24 09:58:45 +0800

Seen: 242 times

Last updated: Dec 26 '08

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