0

Construct an instance of an object on bind in zul

asked 2017-06-25 09:15:06 +0800

JustinFrost gravatar image JustinFrost
145 1 6

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.

delete flag offensive retag edit

Comments

Using the core taglib of zk you can use the 'new' for creating an instance

chillworld ( 2017-06-25 09:23:33 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-06-26 01:59:38 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2017-06-26 02:00:34 +0800

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

link publish delete flag offensive edit

Comments

Awesome - thanks Robert. I knew there was probably a way.

JustinFrost ( 2017-06-26 08:19:19 +0800 )edit
Your answer
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
1 follower

RSS

Stats

Asked: 2017-06-25 09:15:06 +0800

Seen: 34 times

Last updated: Jun 26 '17

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