0

[HELP] jQuery widget ZK5.0.2

asked 2010-05-26 01:38:32 +0800

darkoasis09 gravatar image darkoasis09
63 2

updated 2010-05-26 01:43:23 +0800

Hi,

I've been receiving an ample amount of help from this community

especially when it comes from migrating from ZK3 to ZK5 issues.

I would like to ask for another help with this issue i am currently facing.

---------------------------------------------------------
I encounter a problem using jquery, although i've already found a work around.

but i am thinking maybe the problem is in my code, so i am hoping you could help me fix it.

I am using jquery to validate and display messages on the client side..

the problem comes when i am using a window pop-up form...

it seems that the jquery is not invalidating the form even if i already invoked it, instead

it adds another component to the widget so as making it an array of widget..

the codes are here as follows:



index.zul
<?page title="Auto Generated index.zul"?>
<zk>
	<window title="Hello World!!" border="normal" width="200px" apply="test.IndexCtrl">
	<panel>
		<panelchildren>
	<script type="text/javascript"> <![CDATA[
			function showError(widget, msg) {
			var html = "<div ><span>*"+ msg +"</span></div>";
			jq(widget[widget.length-1]).after(html);
			console.log(widget);
		}
	]]>
	</script>
			<button id="btnShow" label="Show Window" />
		</panelchildren>
	</panel>
	</window>
</zk>



IndexCtrl.java
package test;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Window;

public class IndexCtrl extends GenericForwardComposer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9200331251694400936L;

	public void onClick$btnShow() {
		try {
			Window winForm = (Window) Executions.getCurrent().createComponents(
					"/window.zul",
					null, null);
			winForm.invalidate();
			winForm.doModal();
			winForm.detach();
			winForm=null;
		} catch (SuspendNotAllowedException e) {
			Clients.clearBusy();
			e.printStackTrace();
		} catch (InterruptedException e) {
			Clients.clearBusy();
			e.printStackTrace();
		} catch (Exception e) {
			Clients.clearBusy();
			e.printStackTrace();
		}
	}
}



window.zul
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="windowForm" title="new page title" width="400px" border="normal" apply="test.WindowCtrl">
	<grid>
		<columns>
			<column width="20%" />
			<column />
		</columns>
		<rows>
			<row>
				<label value="Firstname" />
				<textbox id="txtFirstName" width="99%" />
			</row>
			<row>
				<label value="Latname" />
				<textbox id="txtLastName" width="99%" />
			</row>
			<row>
				<button id="btnOk" label="OK" />
				<button id="btnCancel" label="Cancel" />
			</row>
		</rows>
	</grid>
</window>
</zk>


package test;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

public class WindowCtrl extends GenericForwardComposer {
	private static final long serialVersionUID = -1374098330647731875L;
	private Window	windowForm;
	private Textbox txtFirstName;
	private Textbox	txtLastName;
	
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		
		windowForm.setTitle("Please enter your name");
	}
	
	public void onClick$btnOk() {
		String msg = "";
		if(txtFirstName.getText().trim().length()==0) {
			msg += " showError(jq('$txtFirstName'), 'Firstname is mandatory.');";
		}
		
		if(txtLastName.getText().trim().length()==0) {
			msg += " showError(jq('$txtLastName'), 'Lastname is mandatory.');";
		}
		
		if(msg.trim().length()>0) {
			Clients.evalJavaScript(msg);
		} else {
			Clients.evalJavaScript("alert('Hello " + txtFirstName.getText().trim() + " " + txtLastName.getText().trim() + "');");
			windowForm.detach();
		}
		System.out.println(msg);
	}
	
	public void onClick$btnCancel() {
		windowForm.detach();
	}
}

You can check the firefox console and notice that whenever you reload the window the next time,

it adds the new widget at the end of the widget array...

like this

[null, null, input#z_d__c1.z-textbox]
[null, null, input#z_d__f1.z-textbox]

that's why my workaround is using this piece of code

jq(widget[widget.length-1])

before appending the error message or even validating the component in the client

but i was hoping to achieve the same result using only this code

jq(widget)

by the way i am using ZK 5.0.2
hope you help me again

many thanks,

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-05-26 20:17:23 +0800

darkoasis09 gravatar image darkoasis09
63 2

Hi,

does nobody here face the same problem?

thanks

link publish delete flag offensive edit

answered 2010-06-01 23:00:59 +0800

darkoasis09 gravatar image darkoasis09
63 2

Hi all,

Is this considered a bug,

or is it my code, or its just the way ZK 5 behaves for window components...


thanks,

link publish delete flag offensive edit

answered 2010-06-02 06:14:54 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

I test with your example, and it works well.
Please use the latest ZK 5.0.3-FL to give it a try, which can be found - http://www.zkoss.org/download/freshly/

link publish delete flag offensive edit

answered 2010-06-02 20:23:37 +0800

darkoasis09 gravatar image darkoasis09
63 2

Hi jumperchen,

I'll give it a try, then i'll let you know.

thanks

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: 2010-05-26 01:38:32 +0800

Seen: 850 times

Last updated: Jun 02 '10

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