ZK MVVM binder save with EL-Expression

208 views Asked by At

How to do this with zk MVVM

i want to save a bean but with condition if the type is personal than save into personal, else into company

<textbox value="@save(vm.personal ? vm.masterCifPersonal.cifId : vm.masterCifCompany.cifId)" width="100px" maxlength="10"/>

but when binder save into bean, this exception appear

Illegal Syntax for Set Operation

2

There are 2 answers

0
barracus On BEST ANSWER

My tip is to modify your code and use a temporary var:

<textbox value="@save(vm.temp)" width="100px" maxlength="10"/>

and modify your setter as

void setTemp(Long temp) {
    if(personal) {
        masterCifPersonal.cifId = temp;
    } else {
        masterCifCompany.cifId = temp;
    }
}
0
chillworld On

another solution could be :

ZK 8 and higher :

<if test="@load(vm.personal)">
    <textbox value="@save(vm.masterCifPersonal.cifId)"/> 
</if>
<if test="@load(not vm.personal)">
    <textbox value="@save(vm.masterCifCompany.cifId)"/> 
</if>

ZK 6.5 an higher:

<textbox value="@save(vm.masterCifPersonal.cifId)" visible="="@load(vm.personal)"/>
<textbox value="@save(vm.masterCifCompany.cifId)" visible="="@load(not vm.personal)"/>  

Difference:

The if tag will not render the other tag into the dom while using the visible attribute will render it in the dom.
If personal isn't dynamic you could use the if attribute of the Textbox but the usage is then : if="${vm.personal} because binding will not work
Like this the textbox isn't also rendered into the DOM.