# MVVM : How to use listbox.selectedIndex directly into zul ?

Mychal
151 3

Hi,

my problem is simple. I have a listbox defined like this :

                        <listbox id="refTypeL"
selectedItem="@bind(vm.refTypeSelected)"
mold="select"
width="150px"
sclass="h3Field" >
<template name="model" var="itemRefT">
</template>
</listbox>


And i would like to show a div depending on selection in listbox... I try this :

<div sclass="h3" visible="${refTypeL}.selectedIndex eq 2">  But selectedIndex is not refreshed. Any idea ? Thank you delete retag edit ## 2 Answers Sort by » oldest newest most voted answered 2013-07-19 06:08:30 +0800 sjoshi 3493 1 8 http://zkframeworkhint.bl... What i can suggest you, 1-First create a class variable in View Model. 2-Create a new method and Notify This Variable when any item selected and inside this method you can write the logic to get selectedindex and update your class variable and bind this variable your zul page . 3- Now in zul the above bind variable will be use in div's visible attribute . ## Comments yeah, by viewmodel no pb exactly as i expected. With the same example, no need to create a variable we already had it, here the solution: visible="@load(vm.refTypeSelected.type eq 'test')" ( 2013-07-29 15:25:57 +0800 )edit answered 2013-07-19 11:16:55 +0800 nsharma 917 1 11 Hi mychal, do it like : <div sclass="h3" visible="${refTypeL.selectedIndex eq 2}">


reply if this works.Otherwise do as @sjoshi suggests,that's also a good idea to have flexibility in your code.

i have tried ${refTypeL.selectedIndex} eq 2 and${refTypeL.selectedIndex eq 2}. Nothing is working. The pb is that selectedIndex is not refreshed. yeah the solution in viewmodel is easy to apply, but i was thinking that EL expression were there to gain time and reduce code :p Thank you anyway ;-)

( 2013-07-29 15:16:56 +0800 )edit
[hide preview]