-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
we are starting a new project and want to use a ServiceServer. Therefor we exchange XML-Data with the server. A groovx-client-class builds an array with data from class GroovyBean:
package de.lkv.basis.container; /** * GenGroovyBean ist eine generische GroovyBean, die mit Hilfe von MOP Setter und Getter-Methoden generisch * verwaltet */ /** * @author paulsen * */ public class GenGroovyBean{ def dmap = [:] def internid = 0; def id = ""; def pfad = ""; static int lfdnr = 0; GenGroovyBean(){ internid = ++lfdnr } public invokeMethod(String method, args){ if (method.startsWith("set")){ String key = method.substring(3).toLowerCase(); String value = args[0]; dmap.put(key,value); } else if (method.startsWith("get")){ String key = method.substring(3).toLowerCase(); return dmap.get(key) } } public String toString(){ return "GGB:"+ pfad + ": Map: "+dmap; } static void main(args) { def gb = new GenGroovyBean(); Map xmap = [test : "gut" , lom : 276000578333333 , zugdat : "2008-08-01" ] gb.setDmap(xmap) println("1:" + gb.getDmap()); gb.setName("Bertha"); gb.setRasse(1); println("2:" + gb.getDmap()); println("3:" + gb.getRasse()); println("4:" + gb.getLom()); println("5:" + gb.getName()); } }
We tried to use it in our zk-skripts and made different approaches. Best practice would be to use this bean like an java bean. But that does not work. Has anybody an idea how to implement this 'GenericBean in ZK.
Here our best results:
1:
<?xml version="1.0" encoding="UTF-8"?> <?page zscriptLanguage="Groovy"?> <window border="normal" > <zscript> import de.lkv.basis.service.* def hm = [:]; hm.put("BETRIEB","75020056"); hm.put("TIERSTATUS","A"); hm.put("ABGDAT","2007-01-01"); def service = new de.lkv.basis.service.ServiceStarter("localhost",8091); service.starteService("servicerunner","tierliste/aufruf_tierliste.xml",hm); al = service.getPfad(0,"BETRZUG"); // sst = new service.ServiceStarter() // sst.getDatenFromXmlFile("/home/spittel/workspace_zk/Galaxy/resources/ergsmall.xml") // al = sst.getPfad(0,"BETRZUG"); // ArrayList </zscript> <textbox id="waskommt" value="da ist nichts " /> <listbox id="klb" rows="20" mold="paging" width="50%" model="@{al}" onSelect="tbLom.value=self.selectedItem.value.dmap.lom; tbZugdat.value=self.selectedItem.value.dmap.zugdat; tbName.value=self.selectedItem.value.dmap.name;" > <listhead> <listheader width="20%" label="LOM" sort="auto" /> <listheader width="20%" label="Zugangsdatum" sort="auto" /> <listheader width="20%" label="Name" sort="auto" /> </listhead> <listitem forEach="${al}" value="${each}" > <listcell label="${each.dmap.lom}" value="LOM"/> <listcell label="${each.dmap.zugdat}" value="ZUGDAT"/> <listcell label="${each.dmap.name}" value="NAME"/> </listitem> </listbox> <grid width="50%"> <rows> <row> <label value="gewaehlte LOM" /> <textbox id="tbLom" value="${selected.dmap.lom}" /> </row> <row> <label value="Zugangsdatum" /> <textbox id="tbZugdat" value="" /> </row> <row> <label value="Name" /> <textbox id="tbName" value="" /> </row> <row> <label value="Hole Stammdatenblatt" /> <button label="start" onClick="tbLom.value = selected.Lom"> </button> </row> </rows> </grid> </window>
2:
<?xml version="1.0" encoding="UTF-8"?> <?page zscriptLanguage="Groovy"?> <window id="x" border="normal" > <zscript> import de.lkv.basis.service.*; import de.lkv.basis.container.*; import java.util.*; HashMap hm = new HashMap(); hm.put("BETRIEB","75020056"); hm.put("TIERSTATUS","A"); hm.put("ABGDAT","2007-01-01"); ServiceStarter service = new de.lkv.basis.service.ServiceStarter("localhost",8091); service.starteService("servicerunner","tierliste/aufruf_tierliste.xml",hm); ArrayList al = service.getPfad(0,"BETRZUG"); // public class MyItemRenderer implements ListitemRenderer { // public void teste(){ // println("DAS ist ein Test"); // } // public void render(Listitem li, Object data) { // println("RENDERER:"); // if (data == null) println("NO DATA"); // else println(data); // println(((de.lkv.basis.container.GenGroovyBean)data).getLom()); // new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getLom()).setParent(li); // new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getZugdat()).setParent(li); // new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getName()).setParent(li); // } // } // def ir = new MyItemRenderer(); </zscript> <textbox id="waskommt" value="da ist nichts " /> <listbox id="klb" rows="20" mold="paging" width="50%" model="@{al}" > <attribute name="itemRenderer"> <zscript> new MyItemRenderer(){ public void render(Listitem li, Object data) { println("RENDERER:"); if (data == null) println("NO DATA"); else println(data); println(((de.lkv.basis.container.GenGroovyBean)data).getLom()); new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getLom()).setParent(li); new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getZugdat()).setParent(li); new Listcell(((de.lkv.basis.container.GenGroovyBean)data).getName()).setParent(li); } } </zscript> </attribute> </listbox> <grid width="50%"> <rows> <row> <label value="gewaehlte LOM" /> <textbox id="tbLom" value="${selected.dmap.lom}" /> </row> <row> <label value="Zugangsdatum" /> <textbox id="tbZugdat" value="" /> </row> <row> <label value="Name" /> <textbox id="tbName" value="" /> </row> <row> <label value="Hole Stammdatenblatt" /> <button label="start" onClick="tbLom.value = selected.Lom"> </button> </row> </rows> </grid> </window>
Hello,
Sorry. I forgot to tell you, that the second approach will not work. I also tried to define the class MyItemRenderer implementing the interface in the
first zk-script and use it in the listbox. But then zk doesn't find the class.
Regards flens
Hi,
For MyItemRenderer problem,
there is an example in small talk,
http://www.zkoss.org/smalltalks/databind4/databind4.dsp
and you could see directly below,
<window> <zscript> public class MyItemRenderer implements ListitemRenderer { public void render(Listitem li, Object data) { new Listcell(((Person)data).getFirstName()).setParent(li); new Listcell(((Person)data).getLastName()).setParent(li); } } ListModel model = new SimpleListModel(persons.toArray()); ListItemRenderer itemRenderer = new MyItemRenderer(); </zscript> <listbox model="${model}" itemRenderer="${itemRenderer}" rows="4"/> </window>
Hello,
thank you for the feed back. We have had tried this approach already without success. Prehaps it is usefull to build scripts without the use of the service server. Here are two 2 approaches which only use the GenGroovyBean (see first message), which don't work.
1:
<?xml version="1.0" encoding="UTF-8"?> <?page zscriptLanguage="Groovy"?> <window border="normal" > <zscript> import de.lkv.basis.service.* import de.lkv.basis.container.* ggb1 = new GenGroovyBean(); ggb1.setLom(2760005800000000); ggb1.setName("Bellamia"); ggb2 = new GenGroovyBean(); ggb2.setLom(2760005900000001); ggb2.setName("Atlanta"); ggb3 = new GenGroovyBean(); ggb3.setLom(2760005900000002); ggb3.setName("Santana"); def al = [ggb1,ggb2,ggb3]; println(al); ListModel model = new SimpleListModel(al); </zscript> <listbox id="klb" rows="4" mold="paging" width="50%" > <!-- model="${model}" <listhead> <listheader width="20%" label="LOM" sort="auto" /> <listheader width="20%" label="Name" sort="auto" /> </listhead --> <listitem forEach="@{al}"> <listcell label="${each.Lom}"/> <listcell label="${each.Name}" /> </listitem> </listbox> </window>
2:
<?xml version="1.0" encoding="UTF-8"?> <?page zscriptLanguage="Groovy"?> <window border="normal" > <zscript> import de.lkv.basis.service.* import de.lkv.basis.container.* ggb1 = new GenGroovyBean(); ggb1.setLom(2760005800000000); ggb1.setName("Bellamia"); ggb2 = new GenGroovyBean(); ggb2.setLom(2760005900000001); ggb2.setName("Atlanta"); ggb3 = new GenGroovyBean(); ggb3.setLom(2760005900000002); ggb3.setName("Santana"); def al = [ggb1,ggb2,ggb3]; println(al); public class MyItemRenderer implements ListitemRenderer{ public void render(Listitem li, Object data){ new Listcell(((GenGroovyBean)data).getLom()).setParent(li); new Listcell(((GenGroovyBean)data).getName()).setParent(li); } } ListModel model = new SimpleListModel(al); ListitemRenderer myItemRenderer = new MyItemRenderer(); </zscript> <listbox id="klb" rows="4" mold="paging" width="50%" model="${model}" itemRenderer="${myItemRenderer}" /> </window>
In the first example he doesn't interpret the class GenGroovyBean in
<listitem forEach="@{al}">
<listcell label="${each.Lom}"/>
<listcell label="${each.Name}" />
</listitem>
right.
In the second example which is like your proposal he finds the variable itemRenderer, but can not find the class.
With regards flens (Christian)
Hi,
For the first example,
if you declare the variables Lom and Name in GenGroovyBean class as lom and name,
please modify your code as
<listitem forEach="${al}"> <listcell label="${each.lom}"/> <listcell label="${each.name}" /> </listitem>
For the second one,
I've revised your renderer class and it seems ok,
please try it.
public class MyItemRenderer implements ListitemRenderer{ public void render(Listitem li, Object data){ Listcell listcell1 = new Listcell(); listcell1.setLabel(String.valueOf(((GenGroovyBean)data).getLom())); listcell1.setParent(li); Listcell listcell2 = new Listcell(); listcell2.setLabel((((GenGroovyBean)data).getName())); listcell2.setParent(li); } }
Asked: 2009-05-14 07:39:54 +0800
Seen: 499 times
Last updated: May 15 '09