-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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!
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
BTW - shouldn't the model use a ListModelList or something similar?
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.
Asked: 2011-04-28 22:15:35 +0800
Seen: 632 times
Last updated: May 01 '11