1

ZK Combo box and MVVM [closed]

asked 2015-02-13 10:57:47 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

I am using MVVM. Here is the simple combo box example. When the user select any entry in the list, i want to store the value part (integer) in the view model class integer variable. How we can do that ?

<combobox 
mold="rounded" hflex="1">
<comboitem label="No Listing " value="1" />
<comboitem label="Show Last 30 days Listing by DOE" value="2" />
</combobox>
delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by Senthilchettyin
close date 2015-02-13 16:39:41

4 Answers

Sort by ยป oldest newest most voted
1

answered 2015-02-13 11:30:19 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2015-02-13 16:41:58 +0800

something like this(the 1 and 2 are set in the vm.comboValue) :

<combobox selectedItem="@bind(vm.comboValue)">
    <comboitem label="No Listing " value="1" />
    <comboitem label="Show Last 30 days Listing by DOE" value="2" />
</combobox>

Edit :

You can change the integer in the viewmodel to String, then it would work.

Or you can cast the numbers to integer in the zul like in this fiddle.

Edit 2 (Why is mine fiddle showing error):

change :

import org.zkoss.bind.annotation;

to :

import org.zkoss.bind.annotation.*;

reason : he search for the class annotation in stead of using the whole package.

second :

Your AfterCompose class is ambigious, what means there are 2 classes with that name in the imports.

Now, for MVVM the standard initialisation is to use :

@Init
public void initsetup() }
}

You don't need to use @AfterCompose, only is rare occasions.(I never needed it in projects)

The view, don't put it there if you don't use it, it's just making the application heavier.

Your fiddle will still not work with these 2 changes because you have still an String in the zul and Integer in the viewmodel.
The above fiddle of me without the initialisation was already set up for Integer usage(old one).
I just have changed mine fiddle so it works wityh the initialisation in Integer.

Greetz chill.

link publish delete flag offensive edit
0

answered 2015-02-13 11:35:45 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

Ok . One More question

What makes the difference when we use value and selected item as show here

<combobox value = "@bind(vm.comboValue)" selectedItem="@bind(vm.comboValue)">
    <comboitem label="No Listing " value="1" />
    <comboitem label="Show Last 30 days Listing by DOE" value="2" />
</combobox>
link publish delete flag offensive edit
0

answered 2015-02-13 11:47:03 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

updated 2015-02-13 11:50:13 +0800

Having some problem. After selecting, the entry disappears.

Here is the fiddle

Source Fiddle

link publish delete flag offensive edit

Comments

nah, your problem is actually you set the 1 in the zul => String. In your viewmodel you use Integer. There is an autocasting for the save but not for the load, as you call the setValue, getValue is also triggered. So as long you don't have to set the index yourself in the viewmodel, just use @save.

chillworld ( 2015-02-13 12:13:01 +0800 )edit
0

answered 2015-02-13 12:40:11 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

Can you please check the fiddle, it shows error when we use MVVM annotation. I am not expert in using fiddle :)

link publish delete flag offensive edit

Comments

sorry senti, with copy past at the second combobox there was a ( instead of $

chillworld ( 2015-02-13 12:53:51 +0800 )edit

But why my fiddle is showing java error ?

Senthilchettyin ( 2015-02-13 14:39:20 +0800 )edit

edited the answer

chillworld ( 2015-02-13 15:18:30 +0800 )edit

Question tools

Follow

RSS

Stats

Asked: 2015-02-13 10:57:47 +0800

Seen: 27 times

Last updated: Feb 13 '15

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