javamodel-view-controllerdata-bindingzk

Zk framework 6.5.3 binding with composer using E.L


I am using this code. Which is working very good.

<window id="win" xmlns:w="http://www.zkoss.org/2005/zk/client" apply='MyComposer'>
<textbox value="@{$composer.student.name}"/>

But i want to use something like this

<cell width='$composer.fullWidth?"70%":"50%"'>

In my composer I have a boolean fullWidth with the proper getter but I cannot reference it with the composer. I have tried a lot but nothing seems to work.

I have try

<cell width='@{$composer.fullWidth}?"70%":"50%"'>
<cell width='{$composer.fullWidth}?"70%":"50%"'>
<cell width='@{composer.fullWidth}?"70%":"50%"'>

Another question: if I have a code like this:

<textbox id='test' if='expression'/>

How can I the or use the if using Java code? Is it not possible?

Something like:

test.setIf(boolean???????)

Solution

  • First of all, please use correct MVVM.
    The @{} is a buggy version from zk6.0 to created MVVM.
    You even can't find that back in the ZK documentation!

    With real MVVM :

    @load(vm.fullwidth?'70%':'50%')
    

    Second question:
    The if attribute a special one. Only static binding works here because if it's evaluated false, the component will not been rendered in the DOM.
    So either use visible, or use in javacode an extra check if you may add this component to the DOM.