-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everyone,
I am building my web application with CDI and I want to inject my CDI beans into the controller without using @WireVariable. Is that possible in ZK? Every thread that I have searched only deals with @WireVariable which I do not prefer at all.
Is there any way to link my ZK frontend layer with my business layer using @Inject ?
I appreciate any kind of help!
regards, Ethernut
Yes it's possible, but not recommended.
Extend all your VM's from this :
package be.chillworld.web.common;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
*
* @author chillworld */
public abstract class AbstractVM {
public AbstractVM() {
this.autowire(this);
}
protected final void autowire(Object object) {
this.getApplicationContext().getAutowireCapableBeanFactory()
.autowireBean(object);
this.getApplicationContext().getAutowireCapableBeanFactory()
.initializeBean(object, null);
}
/**
* Gets the application context.
*
* @return the application context
*/
protected final ApplicationContext getApplicationContext() {
return WebApplicationContextUtils
.getRequiredWebApplicationContext(Executions.getCurrent()
.getDesktop().getWebApp().getServletContext());
}
}
Chill.
Asked: 2018-02-24 21:40:07 +0800
Seen: 10 times
Last updated: Feb 26 '18