-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi! this is my first post,
I read some codes that talks about to use the variables from java to zul code:
<listheader label="@{Class.variable}" />
How can I do it? I tried it but not works.
Thanks for help!
Marky,
Here is an extremely simple example:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript> String header1 = new String("Fruits"); String header2 = new String("Color"); public class Fruit { private String name; private String color; public Fruit(String n, String c) { setName(n); setColor(c); } public String getName() { return name; } public void setName(String n) { name = n; } public String getColor() { return color; } public void setColor(String c) { color = c; } } List Fruits = new ArrayList(); Fruits.add(new Fruit("Apple", "Red")); Fruits.add(new Fruit("Orange", "Orange")); Fruits.add(new Fruit("Grape", "Purple")); </zscript> <window style="padding: 25px;"> <listbox id="lb" model="@{Fruits}"> <listhead> <listheader label="@{header1}" style="font-weight: bold; color: #003E7E;"/> <listheader label="@{header2}" style="font-weight: bold; color: #003E7E;"/> </listhead> <listitem self="@{each=Fruit}"> <attribute name="onClick"> alert("You clicked on " + lb.getSelectedItem().getLabel()); </attribute> <listcell label="@{Fruit.name}" /> <listcell label="@{Fruit.color}" /> </listitem> </listbox> </window> </zk>
As Steva77 says, it is always easier for us to help you if you post an example of your code. Please make sure you wrap your code in [code] [/code] blocks.
Welcome to ZK!
Kind regards,
Todd
What are you exaclty trying to achieve?
It seems you are trying to bind the label to a class' variable... but where are you setting it?
Maybe post some code to review.
@ = databinding sign
$ = variable sign
Thanks for the replies. Specifically I try to use the java class, no a script or embedded code in my zul. I'm not sure if this is posible because all of samples that I have seen always use the zul file to do it. I try the fruits code and it works, but doing the same in a java class no. I don't know if that's possible but I need do something like this:
<?page title="new page title" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <window apply="Componentes.PostJava" title="new page title" border="normal"> <label id="label" value="@{value}" visible="true"></label> </window> </zk>
And in my java class:
public class PostJava extends GenericForwardComposer { private static final long serialVersionUID = 1L; String value="new content"; }
Thanks all for help!!
Regards,
Marky
Sure, it can works in plain java. ZK is a JAVA web 2.0 framework.
Look at this thread. There are codes in it who are showing how to implement the databinding mechanism in pure java. methode: initDataBinding()
best
Stephan
uOO!! Thanks people and Stephan! I can use the thread to extract the methods to work in javaclass. I'm very grateful with you.
Kind regards,
Mark.
Asked: 2011-05-13 02:50:27 +0800
Seen: 407 times
Last updated: May 16 '11