0

To use DynaBean with ZKoss

asked 2012-08-31 04:58:23 +0800

zeroho gravatar image zeroho
16 2

Hi All,

May I ask if I can use BeanUtils DynaBeans to wrap data received from NoSQL persistent layer? Since the returned values vary based on user's preference, having DynaBean to work with Zkoss shall be great.

For example.

public class SearchViewModel extends SelectorComposer<Component> {

	private ArrayList<DynaBean> searchList = new ArrayList<DynaBean>();

	public List<DynaBean> getSearchList() {

		

		DynaProperty[] properties = rsdc.getDynaProperties();
		BasicDynaClass bdc = new BasicDynaClass("foo", BasicDynaBean.class, properties);

DynaProperty[] props = new DynaProperty[]{
        new DynaProperty("fn", String.class),
        new DynaProperty("ln",  String.class)
...
      };


    BasicDynaClass dynaClass = new BasicDynaClass("searchresult", null, props);
.... 


		Iterator<DynaBean> rows = results.iterator();
		
                while (rows.hasNext()) {
			DynaBean orow = (DynaBean) rows.next();
			DynaBean row = null;
			try {
				row = bdc.newInstance();
				PropertyUtils.copyProperties(row, orow);
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			}

			searchList .add(row);
		}

		return searchList ;

	}


View Code:


<window  border="normal" apply="org.zkoss.bind.BindComposer"
	viewModel="@id('vm') @init('com.stockta.SearchViewModel')">
	
	
	<listbox  model="@bind(vm.searchList)" emptyMessage="No car found in the result">
		<listhead>
			<listheader label="Stock" />
		</listhead>
		<template name="model">
			<listitem>
				<listcell label="@bind(each.fn)"></listcell>
                                <listcell label="@bind(each.ln)"></listcell>
			</listitem>
		</template>
	</listbox>
</window>


delete flag offensive retag edit
Be the first one to reply this discussion!
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-08-31 04:58:23 +0800

Seen: 88 times

Last updated: Aug 31 '12

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