0

Use JavaClass in zul

asked 2011-05-13 02:50:27 +0800

Marky gravatar image Marky flag of Spain
284 7
http://www.no/havent-doma...

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!

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2011-05-13 10:10:39 +0800

twiegand gravatar image twiegand
1807 3

updated 2011-05-13 10:11:26 +0800

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

link publish delete flag offensive edit

answered 2011-05-13 09:35:22 +0800

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

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.

link publish delete flag offensive edit

answered 2011-05-13 15:37:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

@ = databinding sign
$ = variable sign

link publish delete flag offensive edit

answered 2011-05-13 15:40:08 +0800

twiegand gravatar image twiegand
1807 3

Also, using the $ only happens once and very early in the lifecycle of your screen. It is best used for "static" things like field labels, etc.

link publish delete flag offensive edit

answered 2011-05-16 03:13:13 +0800

Marky gravatar image Marky flag of Spain
284 7
http://www.no/havent-doma...

updated 2011-05-16 03:15:58 +0800

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

link publish delete flag offensive edit

answered 2011-05-16 04:50:12 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

link publish delete flag offensive edit

answered 2011-05-16 06:44:00 +0800

Marky gravatar image Marky flag of Spain
284 7
http://www.no/havent-doma...

updated 2011-05-16 10:22:42 +0800

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.

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-05-13 02:50:27 +0800

Seen: 407 times

Last updated: May 16 '11

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