0

How to use Java ArrayList in ZK

asked 2011-04-28 22:15:35 +0800

Faabass gravatar image Faabass
6

Hello, i'm doing my first proyect in zk but i'm having some problems.

The most important is how to use the object that i have in java code like ArrayList<person> in Zk.
For Example, i have the class object that have nameParson and idPerson, with theis getter and setter (getName, setName, getId, setId)
And i have a java method that return me an ArrayList<person>.

How can i do a combobox, for example, where the Id of the item will be the person id, and de value the person name.

I did the following but it didn'y work.

In java

	public ArrayList<entity.Person> getAllPeople()
	{
		negocio.PersonB oNegocio = new negocio.PersonB();
		return oNegocio.getAllPeople();
	}

In Zk

	<zscript><![CDATA[
		import java.util.ArrayList;
		presentacion.Person oPresentacion = new presentacion.Person();
		ArrayList<entity.Person> oPeople = new ArrayList<entity.Person>();
		oPeople = oPresentacion.getAllPeople();
	]]></zscript>
       <combobox id="box" width="200px" mold="rounded" model="${oPeople}" >
    		<comboitem self="@{each='per'}">
    			<id value="${per.idPerson}" />
    			<label value="${per.namePerson}" />
    		</comboitem>
		</combobox>

Thanks!

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-04-29 02:04:36 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

The classical BeanShell-Interpreter is used to interpret Java code contained in ZK-scripts. Unfortunately classical BeanShell doesn't support generics. There's a fork of the classical BeanShell called BeanShell2 which seems to have added support for generics:

http://code.google.com/p/beanshell2/

Maybe you can switch the bsh.jar from your project with the one from Beanshell2 and see if it works.

On the other hand I would recommend to use Richlets for enabling the full power of Java in combination with ZK:

http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/UI_Composing/Richlet

Cheers, Maik

link publish delete flag offensive edit

answered 2011-04-29 02:49:14 +0800

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

BTW - shouldn't the model use a ListModelList or something similar?

link publish delete flag offensive edit

answered 2011-04-29 07:10:27 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Give this a try:

<zscript><![CDATA[
		import java.util.ArrayList;
		presentacion.Person oPresentacion = new presentacion.Person();
		ArrayList<entity.Person> oPeople = new ArrayList<entity.Person>();
		oPeople = oPresentacion.getAllPeople();
                ListModel dataModel = new SimpleListModel(data);
	]]></zscript>
       <combobox id="box" width="200px" mold="rounded" model="${dataModel}" >
    		<comboitem self="@{each='per'}">
    			<label value="${per.id}" />
    			<label value="${per.name}" />
    		</comboitem>
		</combobox>

As @Steva77 noted, you need a ListModelList. I have not glanced at the source code in awhile, but the combobox might wrap the ArrayList for you, but we'll remove that doubt.
Also, the values for your labels will be turned into getters. I'm not sure you had Person::getIdPerson and Person::getNamePerson given your earlier description of the methods.
And, lastly, I hope you eventually move the code in the zscript to a Controller...zscript is good for testing, not so much for production. Use the MVC paradigm; it's your friend.

link publish delete flag offensive edit

answered 2011-04-29 14:56:50 +0800

Faabass gravatar image Faabass
6

Thanks a lot for your help!
@caclark or someone, could you give me and example of this or any page where i could find more information about how to move the code to a controller and how to use the MVC paradign?

link publish delete flag offensive edit

answered 2011-05-01 19:04:29 +0800

PeterKuo gravatar image PeterKuo
481 2

@Faabass

Please refer to the smalltalk
ZK MVC Made Easy
http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy

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: 2011-04-28 22:15:35 +0800

Seen: 629 times

Last updated: May 01 '11

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