-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
Extends your vm with this:
package your.package;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.zkoss.bind.impl.SystemConverters;
import org.zkoss.zk.ui.Executions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractVM {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
private WebApplicationContext applicationContext;
public AbstractVM() {
this.autowire();
}
private void autowire() {
this.getApplicationContext().getAutowireCapableBeanFactory()
.autowireBean(this);
}
public ApplicationContext getApplicationContext() {
if (applicationContext == null) {
applicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
}
return applicationContext;
}
public ServletContext getServletContext() {
return Executions.getCurrent().getDesktop().getWebApp()
.getServletContext();
}
public void setApplicationContext(WebApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
2 | No.2 Revision |
Extends your vm with this:
package your.package;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.zkoss.bind.impl.SystemConverters;
import org.zkoss.zk.ui.Executions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractVM {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
private WebApplicationContext applicationContext;
public AbstractVM() {
this.autowire();
}
private void autowire() {
this.getApplicationContext().getAutowireCapableBeanFactory()
.autowireBean(this);
}
public ApplicationContext getApplicationContext() {
if (applicationContext == null) {
applicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
}
return applicationContext;
}
public ServletContext getServletContext() {
return Executions.getCurrent().getDesktop().getWebApp()
.getServletContext();
}
public void setApplicationContext(WebApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}