Revision history [back]

click to hide/show revision 1
initial version

answered 2013-11-18 09:57:29 +0800

chillworld gravatar image chillworld flag of Belgium

https://github.com/chillw...

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;
}

}

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;
}

}

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