Reading and applying properties from Composite Component

asked 2018-06-24 21:00:54 +0800

psinalberth gravatar image psinalberth
52 5


I have a component named Foobox and a Java class with the same name. Inside foobox.zul there is a Window, already wired and I'm trying to put a label inside and set its value by loading a 'bar' property from Foobox.java like ...

<window id="_window" width="80%">
    <label value="@load(bar)" />

... but it's not working. Is there a way to do that or should I create a viewmodel for Foobox to achieve that?

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted

answered 2018-06-25 10:23:50 +0800

cor3000 gravatar image cor3000
4079 1 7
ZK Team

If you say value="@load(bar)" it will simply look for a variable in the current available scopes (e.g. component, page, desktop, session, application, spring ...).

According to your explanations you never set such a scoped variable (or added a custom variable resolver - that might resolve variables from component properties). So I'd say everything works as it should. No variable in scope -> no value.

Technically what you'd need based on your descriptions (to access the component property directly) is this:

<window id="_window" width="80%"> <label value="@load(_window.parent.bar)"/> </window>

You could declare viewModel="@id('someVM')" which is then available as a variable in the component scope below your window component. But any other scoped attribute would work too, as a separate view model/binder is maybe too expensive depending on how often this component is repeated. So you could just set a component scoped attribute inside your composite component.

this.setAttribute("bar", "some label value");

(this is equivalent to <custom-attributes bar="some label value"/>)

Here a single zul demonstration of the 2 approaches.

In the end I am still not fully convinces that this will give the expected results, since you weren't very specific. So if this doesn't match at all. I'll be happy to answer more detailed questions.

link publish delete flag offensive edit


Hi! I used this.setAttribute("bar", bar, COMPONENT_SCOPE);, it seems cleaner for me. I intend just get an object or a property from main VM and put it inside of Foobox, just a label or something like that. It works for me! Thanks!

psinalberth ( 2018-06-25 19:38:37 +0800 )edit

you're welcome

cor3000 ( 2018-06-26 17:43:30 +0800 )edit

@cor3000, Could you reopen this question? I have a new doubt, but involves EL Expressions, but the scope is the same component.

psinalberth ( 2018-06-27 17:59:16 +0800 )edit

ok reopened

cor3000 ( 2018-06-27 18:07:53 +0800 )edit

answered 2018-06-27 18:31:44 +0800

psinalberth gravatar image psinalberth
52 5

updated 2018-06-27 18:35:05 +0800

Thanks! I used setAttribute(...) to "turn visible" the properties I needed. Now, I'm trying to fill a listbox with some data by using model tag and template.

In lookupbox, I'm able to set the column labels, column values and data set. If my property is "primitive" (String, Integer, ...) I can get its value, but when I try to get object.property an exception is thrown, because cannot find object.property. In fact there is no reference any property with that name. I found a class that resolve a property, I'm pretty sure its name is XelResolver.

So, what I'm trying to achieve now is how to access a property from an object inside another object by using an EL Expression or something else. I'd appreciate if you could take a look at this fiddle: http://zkfiddle.org/sample/9dlefj/7-lookupbox

link publish delete flag offensive edit

answered 2018-06-27 20:27:03 +0800

cor3000 gravatar image cor3000
4079 1 7
ZK Team

a syntax like obj['mother.name'] will not search for a nested property and there is no EL syntax that helps here. You could implement a custom EL function that does what you need using apache.commons PropertyUtils or some of ZK internal classes

here your example made runnable showing this (please provide a runnable example next time as it takes quite some time to add missing bits before even adding a solution)

I also took the freedom to pass EL lists instead of comma separated Strings as your colNames and colValues

link publish delete flag offensive edit


Sorry, I forgot to fix my code.I'll try to create this custom function to do that. Thanks again!

psinalberth ( 2018-06-27 21:12:20 +0800 )edit

another way could be to use org.apache.commons.beanutils.PropertyUtils which has a getNestedProperty helper

cor3000 ( 2018-06-28 09:29:06 +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

1 follower



Asked: 2018-06-24 21:00:54 +0800

Seen: 10 times

Last updated: Jun 27

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