ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

getValue from Label

kidleo
7 Feb 2012 21:31:29 GMT
7 Feb 2012 21:31:29 GMT

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.

paowang
8 Feb 2012 01:23:03 GMT
8 Feb 2012 01:23:03 GMT

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:


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>

kidleo
8 Feb 2012 16:41:28 GMT
8 Feb 2012 16:41:28 GMT

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).

twiegandTop Contributor
9 Feb 2012 23:46:45 GMT
9 Feb 2012 23:46:45 GMT

kidleo,

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


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

kidleo
10 Feb 2012 08:48:15 GMT
10 Feb 2012 08:48:15 GMT

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

nbdhirwani
10 Apr 2012 09:42:46 GMT
10 Apr 2012 09:42:46 GMT

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

twiegandTop Contributor
10 Apr 2012 19:49:52 GMT
10 Apr 2012 19:49:52 GMT

Nirav,

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

Regards,

Todd

nbdhirwani
11 Apr 2012 06:41:12 GMT
11 Apr 2012 06:41:12 GMT

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

twiegandTop Contributor
11 Apr 2012 15:01:15 GMT
11 Apr 2012 15:01:15 GMT

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

nbdhirwani
12 Apr 2012 11:54:10 GMT
12 Apr 2012 11:54:10 GMT

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?

twiegandTop Contributor
12 Apr 2012 14:46:08 GMT
12 Apr 2012 14:46:08 GMT

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