1

How can Use View Model in Window rather than Apply?

asked 2012-11-09 10:09:52 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I dont want use apply attribute with foreach Can it possible to use viewModel in place of apply

 <zk xmlns:x="xhtml" xmlns:zk="zk">
 <window border="normal" title="hello" apply="pkg$.TestComposer">
         
         <div>Welcome to ZK Fiddle , run it right now!</div>
         
       <zscript>
         List list =new ArrayList();
         list.add("1");
         list.add("2");          
          List list1 =new ArrayList();
         
          list1.add("3");
         list1.add("4");
         
         Map a = new HashMap();
         a.put("key1", list);
             a.put("key2", list1);
           
   </zscript>
 
   <zk forEach="${a}">
     
     <label value="${each.value}"/> <separator/>
   </zk>
 </window>
</zk>
 
 

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2012-11-09 10:25:34 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

I think everything you need is at http://books.zkoss.org/wiki/ZK_Getting_Started/Get_ZK_Up_and_Running_with_MVVM...

link publish delete flag offensive edit

answered 2012-11-09 11:42:58 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I think i am not able to clear my issue i have to use same code only change will be i will want to use ViewModel with foreach because i am using Map so Model not able to iterate map
thanks

link publish delete flag offensive edit

answered 2012-11-15 13:15:26 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Can anyone know how can i resolve this issue

link publish delete flag offensive edit

answered 2012-11-16 04:32:14 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

@Natividaddly What do you mean by resolved ? this question asked by me and still it is not resolved please dont post anything in any thread if it is not relates to you
thanks

link publish delete flag offensive edit

answered 2012-11-16 05:25:45 +0800

rickcr gravatar image rickcr
704 7

@sjoshi...

//might be typos here.. but you get the idea...

public class YourViewModel {
 
	private List<Employee> employees;

	public List<Employee> getEmployee() {
		something.returnListofEmployees();
    }
}

//ZUL

<window title="Your Page" 
   apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') 
   @init('com.foo.YourViewModel">
	
		<vlayout children="@load(vm.employees)">
			<template name="children">
				<label value="@load(each.name)"/>
			</template>
		</vlayout>
</window>

link publish delete flag offensive edit

answered 2012-11-16 06:02:11 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Do you think children attribute will work with Map i am using foreach because i have a Map and forEach working Fine with Map

link publish delete flag offensive edit

answered 2012-11-16 16:19:46 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

@Benbai did you update anything for my issue? I did not get any of your reply but forum showing you posted something.

link publish delete flag offensive edit

answered 2012-11-19 06:21:44 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Any one know how can i resolve this issue

link publish delete flag offensive edit

answered 2012-11-19 14:21:47 +0800

rickcr gravatar image rickcr
704 7

updated 2012-11-19 14:22:12 +0800

@Sjoshi, 'm not trying to be a smart ass but I'm guessing your pretty new to Java? Have you looked at the Map API? http://docs.oracle.com/javase/6/docs/api/java/util/Map.html

A map has methods like "entrySet()" of "values()" so you can just expose those in your ViewModel depending on what you need.

If you just need the values of your map (as your example shows) just add this to your ViewModel:


public Collection<YourObject> getMyMapValues() {
       return myMap.values();
}

Then use it like any other Collection in your template.

Do you need the key and the value? If you do expose EntrySet...


public Set getMyMapEntrySet() {
       return myMap.entrySet();
}

To use the latter...

<listbox id="foo" model="@load(vm.myMapEntrySet)".....

<template name="model" var="item">
	<listitem  >
		<listcell label="@load(item.key)"></listcell>
		<listcell label="@load(item.value)"></listcell> 
	</listitem>
</template>

might be other ways to use the entrySet or values property of a map directly within the zul listbox, but considering it's only 3 lines of code to add to your ViewModel to do the above, I wouldn't sweat it.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-11-09 10:09:52 +0800

Seen: 189 times

Last updated: Nov 19 '12

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