0

Help on ZK_MVC_Made_Easy

asked 2012-04-24 09:45:30 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

I am just going thru ZK_MVC_Made_Easy

Here is my zul content


<?page title="Example1" contentType="text/html;charset=UTF-8"?>
<zk>
<label
value=" Two input textboxes for the user to input First Name and Last Name. The Full Name will be automatically updated when either input textbox changed
http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy
Implements composer interface where we need add event listeners"
style="font-size : 18px;font-family: verdana,arial,sans-serif;" />
<separator />
<window title="MVC Pattern" border="normal" width="300px" apply="com.me.Example1">
<grid>
<columns>
<column label="" />
<column label="" />
</columns>
<rows>
<row>
First Name :
<textbox id="firstName" forward="onChange=firstname_change"/>
</row>
<row>
Last Name :
<textbox id="lastName" forward="onChange=lastname_change"/>
</row>
<row>
Full Name :
<textbox id="fullName" />
</row>

</rows>
</grid>
</window>
</zk>

Here is my composer

package com.me;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.util.Composer;
import org.zkoss.zul.Textbox;

public class Example1 implements Composer {

private Textbox firstName;
private Textbox lastName;
private Textbox fullName;

@SuppressWarnings("unchecked")
public void doAfterCompose(Component win) throws Exception {
firstName = (Textbox) win.getFellow("firstName");
lastName = (Textbox) win.getFellow("lastName");
fullName = (Textbox) win.getFellow("fullName");

// define and register event listeners
win.addEventListener("firstname_change", new EventListener() {
public void onEvent(Event event) throws Exception {
fullName.setValue(firstName.getValue() + " "
+ lastName.getValue());
}
});
win.addEventListener("lastname_change", new EventListener() {
public void onEvent(Event event) throws Exception {
fullName.setValue(firstName.getValue() + " "
+ lastName.getValue());
}
});
}
}


When i run it, it gives me the following error

org.zkoss.zk.ui.UiException: Not an event name: firstname_change
org.zkoss.zk.ui.sys.ComponentsCtrl.parseEventExpression(ComponentsCtrl.java:245)
org.zkoss.zk.ui.sys.ComponentsCtrl.applyForward0(ComponentsCtrl.java:312)
org.zkoss.zk.ui.sys.ComponentsCtrl.applyForward(ComponentsCtrl.java:273)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:824)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:767)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:676)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:640)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:813)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:767)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:67


Actually i changed only the event name as per the example from forward="onChange=onFirstName" to onChange=firstname_change

is there any naming pattern we need to follow for the event naming ?????????????

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2012-04-26 11:28:38 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi Matze2

Thank you. It works now. I used setAttribute and problem solved.
But only thing, i do not understand the flow. let me Explain in my words. Please correct me if am wrong

1 <textbox id="firstName" value="@{ex1.firstName}"/>
By the above statement, zk engine will go look the composer ex1 object and from there it will go and search for getter method which by the naming pattern
getfirstName ?

2. If that is the case, i have changed in the EL, but still my getter method is as follows
public String getLastName() {
return lastName;
}

here, you can see still it is started with captial letter only. Then how it works ????????/

Here is my modified code
Example1.jul

code: null
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <?page title="MVC Data binding" contentType="text/html;charset=UTF-8"?> <zk> <separator /> <window title="MVC Data binding" border="normal" width="700px" apply="mypack.Ex1Controller"> <grid> <columns> <column label="" /> <column label="" /> </columns> <rows> <row> First Name : <textbox id="firstName" value="@{ex1.firstName}"/> </row> <row> Last Name : <textbox id="lastName" value="@{ex1.lastName}"/> </row> <row> Address : <textbox id="address" value="@{ex1.address}"/> </row> </rows> </grid> </window> </zk>
</p><p>Ex1Controller.java<div style="class=code" class="code"><pre><div class="error">code: null</div>package mypack;

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

@SuppressWarnings("rawtypes")
public class Ex1Controller extends GenericForwardComposer {

	private static final long serialVersionUID = 1L;
	Ex1Modal ex1 = new Ex1Modal();
	@SuppressWarnings("unchecked")
	public void doAfterCompose(Component comp) {
		try {
			super.doAfterCompose(comp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // wire variables and event listners
		
		
		ex1.setFirstName("John");
		ex1.setLastName("Smith");
		ex1.setAddress("1st Street");
		comp.setAttribute("ex1", ex1);
	}

}

Here is my Ex1Modal.java

package mypack;

public class Ex1Modal {
	private String firstName = "";
	private String lastName = "";
	private String address = "";

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

}

And also, as per the document
still the following throws error

<zk>
<window apply="org.zkoss.demo.MyComposer, org.zkoss.zkplus.databind.AnnotateDataBindingComposer">
</window>
</zk>


Any way, thank you very for your help.

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-04-24 09:45:30 +0800

Seen: 429 times

Last updated: Apr 26 '12

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