0

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
6280 2 7

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
0

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

cor3000 gravatar image cor3000
6280 2 7

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 ...>
</if>

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 ...>
  </template>
</div>
link publish delete flag offensive edit

Comments

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

Follow
1 follower

RSS

Stats

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

Seen: 9 times

Last updated: Oct 20 '21

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