Skip to Content
0

Is there any possibility in "Component SDK Development" to fire events in contribution.ztl?

Dec 07, 2017 at 10:35 AM

89

avatar image

Hi,

I'm developing a "Component SDK" for the Lumira Designer. We have a component with an event "onLoad", which should execute some custom Design Studio script.

I know, we can fire this event from client javascript using fireEvent("onLoad"). However, I'm just wondering if there is any simple solution to fire this event from server side (in contribution.ztl).

A workaround is to change a component property in a ztl method, which triggers the component setter on the client side, where we can call fireEvent("onLoad"), which finally results in a server roundtrip again...

As we start on the server side and end on the server side, this way (server-client-server) seems to be unnecessary.

So, is there any possibility to fire events in contribution.ztl on server side?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Mustafa Bensan Dec 07, 2017 at 11:35 AM
0

Florian,

Events are not supposed to be fired from a ZTL function. Although ZTL functions are executed on the server side, they are always called from the client side. Even if it were possible to trigger an event within a ZTL, how were you expecting to trigger the ZTL function from the server side? This is not possible.

I understand your concern about unnecessary server round-trips but this is the way Lumira Designer has been architected so you must develop your SDK component accordingly.

In any case, I would have thought that it makes more sense to trigger an "onLoad" event from the client side because presumably this should occur when the component is initialised or rendered.

Regards,

Mustafa.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Hey Mustafa,

thank you for your quick response.

Okay, you are right, the "onLoad" event was an example. The main idea was to execute predefined ZTL script in combination with custom Designer script without using the eval() function. Therefore, I thought about triggering an event directly from a ZTL function to avoid server round-trips.

But I can understand that this is the way the Lumira Designer has been architected. I just noticed that even the "event handler methods" of the basic components (like BUTTON_1.onClick();) are marked as depracted now. At least, it is coherent now.

Regards,

Florian


0

Hi Florian,

When you say "custom Designer script", do you mean script that the user has defined, or just pre-defined script code that is supplied with your component? If it is the latter, why don't you simply execute that script code within the ZTL?

Regards,

Mustafa.

0

Hi Mustafa,

yes, I mean script that the user has defined...

Something like this (just an example...):

void doSomething(){*
   //Execute some pre-defined script
   APPLICATION.loadDataSources([DS_1, DS_2]);
   //Execute some user-defined script
   try{
     var script = this.userScript;
     eval(script);
   }catch(e){ APPLICATION.createErrorMessage("Error: " + e); }
*}

This would work for certain cases, but I hoped that there is a better solution without using eval().

Regards,

Florian

0

Hi Florian,

My understanding is that you want to execute a user-defined script which is actually dependent on a pre-defined ZTL script being executed first. The architecturally correct way of implementing this is to provide a ZTL script API for the pre-defined script. Then in the appropriate event, the user would execute the component-specific API method script first followed by the user-defined script. I do not recommend using the eval() function to execute the user-defined script within a ZTL function.

The example you have provided is too generic for me to provide a more specific recommendation. If you are able describe a real scenario then I could provide further guidance accordingly.

Regards,

Mustafa.

0

Hi Mustafa,

yeah, that's a good point. I was just wondering if there is a possibility that I do not yet know, apart from a real scenario.

But you are right, there are other ways and possibilities to develop the SDK component according to the architecture.

Thank you.

Regards,

Florian.

0