0

getValue from Label

asked 2012-02-07 21:31:29 +0800

kidleo gravatar image kidleo
81 1

I new on Zk, however I have this question:
If I change the value of Label by javascripts, how I can get this value and treat in the server side?
I always get the declered .zul value.

in my zul file:
<label id="tb" value="pippo" />

when I change pippo wirh pluto in the client side, in the server side i get pippo agein.... this is normal?
I createted the GenericAutowireComposer but it dosen't make effect.

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2012-02-08 01:23:03 +0800

paowang gravatar image paowang
140 6

If you want to interact with ZK at client side, you should read the "ZK Client-side Reference" first:
http://books.zkoss.org/wiki/ZK_Client-side_Reference

I wrote a example here, hope it helps you:

ZKFiddle-Link

index.zul
<zk xmlns:w="client">
<label id="tb" width="250px" value="hello" >
<custom-attributes org.zkoss.zk.ui.updateByClient="true"/>
</label>
<button label="chage at client-side">
<attribute w:name="onClick"><![CDATA[
var tb = zk.Widget.$(jq('$tb')),
val = 'world';
tb.setValue(val);
tb.smartUpdate('value', val);
]]></attribute>
</button>
<button label="get at server-side" onClick="alert(tb.value)"/>
</zk>

link publish delete flag offensive edit

answered 2012-02-08 16:41:28 +0800

kidleo gravatar image kidleo
81 1

This work fine at the clinet side... I had rich this ponit.
I wold like to get the value of the label, changed by javascript using GenericForwardComposer.
I try to be more clearfull:
I have a Label or a textbox in a .zul has in your example.
Then my javascript change the value as in your example.
Then I try to get the actual value using GenericForwardComposer:
public class WindowWorkflowComposer extends GenericForwardComposer{
private Label tb; //the same is also using TextBox

public void onClick$submit(Event event) {
System.out.println("TB value : " + tb.getValue() );
}

}


If I change the value using the keybord, I can get the actual value using a GenericForwardComposer approach,
otherwise if I change the value using javascript the value
remain the previous.

In your example the button whit alert dosn't simulate the server side (I suppose).

link publish delete flag offensive edit

answered 2012-02-09 23:46:45 +0800

twiegand gravatar image twiegand
1807 3

kidleo,

The example from paowang was right on.  With just a bit of tweaking, you get this:

ZKFiddle-Link

TestComposer.java
package jg5ga0c$v1;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;

public class TestComposer extends GenericForwardComposer{

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);

}

public Label myLabel;
public void onClick$submit(Event event) {
alert(myLabel.getValue());
}

}


index.zul
<zk xmlns:w="client">
<window id="main" apply="jg5ga0c$v1.TestComposer" style="padding: 25px;">
<label id="myLabel" width="250px" value="Hello">
<custom-attributes org.zkoss.zk.ui.updateByClient="true" />
</label>
<separator height="10px"/>
<button label="Change via JavaScript">
<attribute w:name="onClick"><![CDATA[
var lbl = zk.Widget.$(jq('$myLabel')),
val = 'World';
lbl.setValue(val);
lbl.smartUpdate('value', val);
]]></attribute>
</button>
<button id="submit" label="Submit"/>
</window>
</zk>

Hope that helps,

Todd

link publish delete flag offensive edit

answered 2012-02-10 08:48:15 +0800

kidleo gravatar image kidleo
81 1

Yes... I Understand Now, and also I had reach the rusult...
This forum is very good, thank you and see you again....

link publish delete flag offensive edit

answered 2012-04-10 09:42:46 +0800

nbdhirwani gravatar image nbdhirwani
9

Hello,

I've been trying to use the solution mentioned in above posts for one of similar cases with HTML widget.

What I've discovered is that the soluton is working fine in ZK Release 5.0.6 but is not working in Release 5.0.7.1.

Can anybody please guide me as we are trying to upgrade our system and I really want this to work after the upgrade is complete.

Its urgent...

Regards
Nirav Dhirwani

link publish delete flag offensive edit

answered 2012-04-10 19:49:52 +0800

twiegand gravatar image twiegand
1807 3

Nirav,

The current version of ZK 5.x is 5.0.11.  Perhaps you could try that version?

Regards,

Todd

link publish delete flag offensive edit

answered 2012-04-11 06:41:12 +0800

nbdhirwani gravatar image nbdhirwani
9

Dear Todd,

Its not gonna help, coz system is being moved to version 5.0.7.1 and the components should work for the same version.

Regards
Nirav

link publish delete flag offensive edit

answered 2012-04-11 15:01:15 +0800

twiegand gravatar image twiegand
1807 3

Nirav,

I just ran the example code in 5.0.7.1 and it works fine.

What results are you getting?  Or, are you trying to do something not related to this thread?

Regards,

Todd

link publish delete flag offensive edit

answered 2012-04-12 11:54:10 +0800

nbdhirwani gravatar image nbdhirwani
9

Dear Todd,

I get a warning similar to mentioned below:

WARNING: Ignore update of content=This is <B><SPAN style="BACKGROUND: yellow"><B>HTML</B> text in ZK HTML control</SPAN></B> from client for class org.zkoss.zul.Html

Is there some configuration parameter that needs to be set for enabling updates from client side?

link publish delete flag offensive edit

answered 2012-04-12 14:46:08 +0800

twiegand gravatar image twiegand
1807 3

Nirav,

I am not aware of any specific parameters that needs to be set (e.g. in the ZK xml file).

If you can post a small, runnable example that reproduces the issue, the community will try to help.

Regards,

Todd

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: 2012-02-07 21:31:29 +0800

Seen: 1,601 times

Last updated: Mar 31 '14

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