-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All,
i'm trying to get the new ZK Spring 3 samples from ZK Spring Essentials / Inject Components in Spring Beans running, but it seems i missed something.
When i try to access the ZUL, i get an error that tells me that it was not able to map the ZUL-Components to my spring composer class:
SEVERE: Servlet.service() for servlet zkLoader threw exception org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopesCtrl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.zkoss.zul.api.Textbox org.zkoss.test.springcomposer.ScopesController.name; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.zkoss.zul.api.Textbox] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329) at org.zkoss.spring.web.context.request.DesktopScope.get(DesktopScope.java:50) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) at org.zkoss.spring.init.CoreVariableResolver.resolveVariable(CoreVariableResolver.java:59)
The listener
<listener> <listener-class>org.zkoss.spring.web.context.CoreContextListener</listener-class> </listener>
Mar 28, 2011 12:31:25 PM org.apache.catalina.core.StandardContext addApplicationListener INFO: The listener "org.zkoss.spring.web.context.CoreContextListener" is already configured for this context. The duplicate definition has been ignored. Mar 28, 2011 12:31:25 PM org.apache.catalina.core.StandardContext addApplicationListener INFO: The listener "org.springframework.web.context.ContextLoaderListener" is already configured for this context. The duplicate definition has been ignored. 12:31:27.175 INFO org.reflections.Reflections - Reflections took 1430 ms to scan 32 urls, producing 2 keys and 5 values
From what i understand the mapping from the composer-bean to the window is working, but it fails to map the window components back to the composer. Where can i start looking to find my issue?
Thanks & Bye,
Chris
Hi ashishd,
the requested files:
ScopesController.java:
package org.zkoss.test.springcomposer; 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.event.Event; import org.zkoss.zul.Messagebox; import org.zkoss.zul.api.Button; import org.zkoss.zul.api.Textbox; @org.springframework.stereotype.Component("scopesCtrl") @Scope("desktop") public class ScopesController extends GenericSpringComposer { @Autowired private SimpleMessageBean msgBean; @Autowired private Textbox name; //@Autowired //private Button setMsgBtn; //@Autowired //private Button showMsgBtn; @EventHandler("setMsgBtn.onClick") public void setMessage(Event evt) { msgBean.setMsg(name.getValue()); } @EventHandler("showMsgBtn.onClick") public void showMessage(Event evt) throws InterruptedException { Messagebox.show(msgBean.getMsg()); } }
springTest.zul:
<?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <window title="Custom Scopes Example - Main Page" border="normal" height="100px" width="400px" apply="${scopesCtrl}"> <label value="Enter Message Text:"></label> <textbox id="name" /> <button id="setMsgBtn" label="Set" /> <button id="showMsgBtn" label="Show Message" /> <button id="showPageBtn" label="Show Window"> <attribute name="onClick"> Window win = (Window) Executions.getCurrent().createComponents("customScopesWindow.zul", null, null); win.doHighlighted(); </attribute> </button> </window>
spring-config-context.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:zksp="http://www.zkoss.org/2008/zkspring/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.zkoss.org/2008/zkspring/core http://www.zkoss.org/2008/zkspring/core/zkspring-core.xsd " > <!-- Spring Annotation Config --> <context:annotation-config /> <context:component-scan base-package="org.zkoss.zkspringessentials.controller,org.zkoss.spring.beans.zkcomponents,org.zkoss.test" /> <zksp:zk-config/> </beans>
As you can see i'm trying to get the sample from the guide running...
Thanks & Bye,
Chris
Hi Christian,
Please use Textbox ZK component instead of Textbox interface i.e.
import org.zkoss.zul.Button; import org.zkoss.zul.Textbox;
import org.zkoss.zul.api.Button; import org.zkoss.zul.api.Textbox;
Asish:
We were using ZK 3.0 to solve a ConcurrentExceptionProblem (we have changed some mails about this) ZKSpring new version solve this issue but there is no possibility now of wiring non-ZK POJOs using @Autowired annotation.
Is this a known limitation? In that case wich is the best place to put SpringUtil.getBeans(...) sentences in order to obtain such POJOS?
Thanks a lot
Regards,
Bruno
Hi Bruno,
Sorry to hear that you are still facing some issue with ZK Spring. If you take a look at custom scopes example from ZK Spring Essentials in that a non-ZK POJO SimpleMessageBean is wired using @Autowired annotation in the composer.
The only difference between wiring non-ZK POJOs and wiring ZK components is that ZK components are lazy initiated i.e. when the very first time composer/controller is requested any ZK compoents wired using @Autowired annotation will be injected with a spring proxy where as all other non-ZK POJO wihin the same controller/composer are injected based on their own configuration so I don't see autowiring of ZK components affecting any other non-ZK POJO injection.
In the mean time I am pretty sure you know this but still want to mention that for @Autowired to work bean package has to be mentioned in the <component-scan/> element of your spring config file.
Otherwise I would appreciate if you could provide me some example that demonstrates this issue then I would be happy to investigate it further.
Hi Ashish,
I send you the login.zul and LoginComposer.java files that correspond to a login that is not working. The access (Acceder) button doesn't seem to send any event because method in the composer does not execute. Can you help us to solve this?
Thanks for your help!!!
Juan
login.zul
<?page title="Acceso al sistema de Expediente Electrónico"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./loginWindow"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<zscript>
java.io.InputStream propsIS=ar.gob.gcaba.ee.satra.pl.LoginComposer.class.getResourceAsStream("/build.properties");
Properties versionProps=new Properties();
versionProps.load(propsIS);
String version=(String)versionProps.get("version");
String build=(String)versionProps.get("build.number");
</zscript>
<window id="loginWindow" width="100%" height="100%"
style="align=center; background-color:#EFEFEF;"
apply="${loginComposer}">
<separator height="10px"></separator>
<box width="98%" align="end">
<label value="- version ${version} - build.${build} -"/>
</box>
<separator height="100px"></separator>
<vbox width="100%" align="center">
<vbox width="100%" height="99%" align="center"
style="border: 2px solid gray; background-color:#FFFFFF;">
<separator height="25px"></separator>
<image src="./imagenes/logoGCBA.jpg" />
<label id="ee.login.label.nombre.sistema"
value="${c:l('ee.login.label.nombre.sistema.value')}"
style="font-size:24px;font-weight:bold "/>
<separator height="10px"></separator>
<label
id="ee.login.label.recomendacion"
value="${c:l('ee.login.label.recomendacion.value')}"
style="font-family:Verdana;font-weight:bold;font-style:italic;color:blue;font-size:12px;" />
<separator height="25px"></separator>
<label id="uiLablMessage" style="${messageStyle}"
value="${errorMessage}" />
<grid width="380px">
<rows>
<row align="center">
<label id="ee.login.label.usuario" value="${c:l('ee.login.label.usuario.value')}"></label>
<textbox id="username"/>
</row>
<row align="center">
<label id="ee.login.label.contrasenia" value="${c:l('ee.login.label.contrasenia.value')}"></label>
<textbox id="password" type="password"/>
</row>
</rows>
</grid>
<vbox align="center">
<separator />
<button id="loginButton" label="${c:l('ee.login.button.value')}" focus="true" />
</vbox>
</vbox>
</vbox>
</window>
</zk>
LoginComposer.java
package ar.gob.gcaba.ee.satra.pl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.zkoss.spring.context.annotation.EventHandler;
import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
import ar.gob.gcaba.co.beans.DatosUsuarioBean;
import ar.gob.gcaba.ee.satra.il.dao.ReparticionSadeDAO;
import ar.gob.gcaba.ee.services.LdapAccessor;
import ar.gob.gcaba.ee.services.UsuariosSADEService;
@org.springframework.stereotype.Component("loginComposer")
@Scope("desktop")
public class LoginComposer extends EEGenericForwardComposer { //EEGenericForwardComposer extends GenericSpringComposer
/**
*
*/
private static final long serialVersionUID = -5999274090235026033L;
@Autowired
private Textbox username;
@Autowired
private Textbox password;
@Autowired
private LdapAccessor ldapAccessor;
//Services
@Autowired
private UsuariosSADEService usuariosSADEService;
@Autowired
private ReparticionSadeDAO reparticionSadeDAO;
@EventHandler("loginButton.onClick")
public void login(Event evt) throws InterruptedException {
if ((username.getValue() == null) || (username.getValue().equals(""))) {
throw new WrongValueException(Labels
.getLabel("ee.login.faltaUsername"));
}
if ((password.getValue() == null) || (password.getValue().equals(""))) {
throw new WrongValueException(Labels
.getLabel("ee.login.faltaPassword"));
}
if (!(ldapAccessor.login(username.getValue(), password.getValue()))) {
Messagebox.show(Labels.getLabel("ee.login.loginIncorrecto"),
Labels.getLabel("ee.general.information"), Messagebox.OK,
Messagebox.EXCLAMATION);
return;
}
if (this.usuariosSADEService.getDatos(username.getValue()) == null) {
Messagebox.show(Labels.getLabel("ee.login.noAutorizado",new Object[]{username.getValue()}), Labels
.getLabel("ee.general.error"), Messagebox.OK,
Messagebox.ERROR);
return;
} else {
DatosUsuarioBean usuario=this.usuariosSADEService.getDatos(username.getValue());
if (usuario==null) {
Messagebox.show(Labels
.getLabel("ee.login.noPoseeReparticion"), Labels
.getLabel("ee.general.information"), Messagebox.OK,
Messagebox.INFORMATION);
return;
} else {
Executions.getCurrent().getDesktop().getSession().setAttribute(
"usernameReparticion", usuario.getReparticion().getCodigo().trim());
Executions.getCurrent().getDesktop().getSession().setAttribute(
"username", username.getValue().toUpperCase());
String usernameNyA = ldapAccessor.buscarUsuarioLdap(username
.getValue());
if (StringUtils.isNotEmpty(usernameNyA)) {
Executions.getCurrent().getDesktop().getSession()
.setAttribute("usernameNyA", usernameNyA);
} else {
Executions.getCurrent().getDesktop().getSession()
.setAttribute("usernameNyA", username.getValue());
}
boolean administrador = ldapAccessor
.isAdministradorCentral(username.getValue());
Executions.getCurrent().getDesktop().getSession().setAttribute(
"admin.central", administrador);
Executions.sendRedirect("./panelUsuario.zul");
}
}
}
public ReparticionSadeDAO getReparticionSadeDAOService() {
return reparticionSadeDAO;
}
public void setReparticionSadeDAOService(
ReparticionSadeDAO reparticionSadeDAOService) {
this.reparticionSadeDAO = reparticionSadeDAOService;
}
public void setUsuariosSADEService(UsuariosSADEService usuariosSADEService) {
this.usuariosSADEService = usuariosSADEService;
}
public UsuariosSADEService getUsuariosSADEService() {
return usuariosSADEService;
}
}
Hi Juan,
Thanks for the test code. Greatly appreciated. Unfortunately it is a bug and I have posted it to ZK Spring issue tracker here. I'll fix it and have a freshly release. I'll notify here once it is ready for download.
Hi all,
I am new with zk and spring. I am getting this ugly error when trying to run this example
the error:
Apr 11, 2011 1:24:50 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove the following @Configuration bean definitions:
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:439)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigurationClasses(ConfigurationClassPostProcessor.java:202)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:176)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:604)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:437)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1276)
at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:558)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:680)
Please help me to solve this problem.
Asked: 2011-03-28 05:38:45 +0800
Seen: 3,299 times
Last updated: Apr 26 '11