Awesome - thanks Robert. I knew there was probably a way.
JustinFrost ( 2017-06-26 08:19:19 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All.
I need to pass a custom object to my component using the @load binding. Is there any way to instantiate an instance of a class on the ZUL page ?
Say I want to @load an instance of CustomObject class passing two fields in the constructor. Something like:
<component property="@load(new CustomObject(parm1,parm2))" />
I know I can construct this on the viewModel and bind it this way, but was hoping to do it on the zul.
Thanks.
you can use one of ZK's core methods (new, new1, new2, new3): https://www.zkoss.org/wiki/ZUML%20Reference/EL%20Expressions/Core%20Methods
using a string class name:
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk>
...
<component property="@load(c:new2('my.pkg.CustomObject', parm1, parm2))" />
using the class directly:
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?import my.pkg.CustomObject?>
<zk>
...
<component property="@load(c:new2(CustomObject, parm1, parm2))" />
or if you have a static factory method (e.g. called newInstance
) you can call it directly (since ZK 8):
<?import my.pkg.CustomObject?>
<zk>
...
<component property="@load(CustomObject.newInstance(parm1, parm2))" />
I hope this helps, if not let me know.
Robert
Awesome - thanks Robert. I knew there was probably a way.
JustinFrost ( 2017-06-26 08:19:19 +0800 )editAsked: 2017-06-25 09:15:06 +0800
Seen: 34 times
Last updated: Jun 26 '17
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]
Using the core taglib of zk you can use the 'new' for creating an instance
chillworld ( 2017-06-25 09:23:33 +0800 )edit