0

ZK Spring autowiring

asked 2011-05-24 03:54:55 +0800

Vovka gravatar image Vovka
15 1

updated 2011-05-24 03:56:09 +0800

Hello All!
I'm trying to run same code as:
ZK Spring Essentials/Working with ZK Spring/Working with ZK Spring Core/Inject ZK Components in Spring Beans

but getting error:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.zkoss.zul.Textbox] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency

and i don't have package "org.zkoss.spring.beans", is it constructed at runtime?

can anybody help me?

my code:
zul:
<?xml version="1.0" encoding="UTF-8"?>

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Autowire ZK Components Example2" border="normal" height="100px"
width="400px" apply="${greetingCtrl}">
<label value="Name:"></label>
<textbox id="name" />
<button id="greetBtn" label="Greet!" />
</window>

java:

package temp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.zkoss.spring.context.annotation.EventHandler;
import org.zkoss.spring.util.GenericSpringComposer;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;

@org.springframework.stereotype.Component("greetingCtrl")
@Scope("desktop")
public class zkess1 extends GenericSpringComposer {

@Autowired
public Textbox name;

// @Autowired
// private Button greetBtn;

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

@EventHandler("greetBtn.onClick")
public void showGreeting(Event evt) throws WrongValueException, InterruptedException {
Messagebox.show("Hello " + name.getValue() + "!");
}
}


web.xml
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<description><![CDATA[TempForms APP]]></description>
<display-name>TempForms</display-name>

<!-- SPRING -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>

<!-- ZK Spring-->
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>
org.zkoss.zk.ui.http.DHtmlLayoutServlet
</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>auEngine</servlet-name>
<servlet-class>
org.zkoss.zk.au.http.DHtmlUpdateServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:zksp="http://www.zkoss.org/2008/zkspring/core"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.zkoss.org/2008/zkspring/core http://www.zkoss.org/2008/zkspring/core/zkspring-core.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="temp,org.zkoss.spring.bean,org.zkoss.zkspringessentials.controller,org.zkoss.spring.beans.zkcomponents"></context:component-scan>
<zksp:zk-config/>


</beans>

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2011-05-24 20:49:28 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi Vovka,
>> i don't have package "org.zkoss.spring.beans", is it constructed at runtime?
Yes

And you have missed the very first step in the configuration i.e. to add

<listener>
    <listener-class>org.zkoss.spring.web.context.CoreContextListener</listener-class>
</listener>

in your web.xml. Note that it should be before the Spring framework ContextLoaderListener declaration.
also would like to recommend to use the latest freshly released on 5/12 to test your codes with. Some critical bugs were fixed in that.

link publish delete flag offensive edit

answered 2011-05-25 03:21:38 +0800

Vovka gravatar image Vovka
15 1

Huge Thanks!

it works, at last.

Amazing! i have looked and checked code hundred times.
But not recognized difference "org.zkoss.spring.web.context.CoreContextListener" vs "org.springframework.web.context.ContextLoaderListener"

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-24 03:54:55 +0800

Seen: 1,127 times

Last updated: May 25 '11

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