How to show listbox only if certain condition

asked 2021-10-20 05:27:41 +0800

daniapesteguia gravatar image daniapesteguia
7 2

updated 2021-10-20 10:11:56 +0800

cor3000 gravatar image cor3000
6270 2 7
ZK Team

Hi, I'm having problems displaying listBox only if certain condition is accomplished.

My classes: editData.zul editDataVM.java

-I have a Integer on editDataVM -> private Integer modelNumber; -modelNumber can be 0 or 1. -I want listbox to be displayed if modelNumber is 1

<listbox if="@load(vm.modelNumber) == 1">

but it's always displaying. How can I do this

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-20 10:24:08 +0800

cor3000 gravatar image cor3000
6270 2 7
ZK Team

updated 2021-10-20 10:26:31 +0800

The documentation for the special if attribute shows that it requires an EL expression and not a @load binding annotation

That's why your usage has no effect. The if attribute is NOT a component propery, and hence no property binding will have an effect. It's an instruction for the ZUL parser/evaluator to include a component in a page or not at all.

<listbox if="@load(vm.modelNumber == 1)">

If you want to evaluate the listbox once statically you can use an EL-expression:

<listbox if="${vm.modelNumber == 1}">

For a dynamic usage ZK (EE) provides the shadow-<if> element.

<if test="load(vm.modelNumber == 1)">
  <listbox ...>

In ZK CE you can use the uglier "single-children-binding" (as I call this). This will evaluate the template if the @load binding result is non null.

<div children="@load(vm.modelNumber == 1 ? 'dummy' : null)">
  <template name="children">
    <listbox ...>
link publish delete flag offensive edit


Hi, thanks a lot for this complete explaination. So, if modelNumber changes to null on my VM, will this change affect the DIV in real time like AJAX or will I have to make other changes?

daniapesteguia ( 2021-11-08 22:48:19 +0800 )edit

the @load-bindings in the 2nd (<if>) and 3rd (single-child-binding) option will update after a notify-change on the modelNumber property via AJAX

cor3000 ( 2021-11-09 09:22:18 +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: 2021-10-20 05:27:41 +0800

Seen: 8 times

Last updated: Oct 20

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