I have browsed Spring integration from Wicket-Stuff, but it is a little
complex... I would like to use "direct" lookup from a super class Page:


public class BaseWebPage extends WebPage {

    private static WebApplicationContext webApplicationContext;

    protected final static Object getBean(String beanName) {
        if (webApplicationContext == null) {

            HttpServletRequest httpRequest = ((WebRequest) RequestCycle.get()
                    .getRequest()).getHttpServletRequest();

            ServletContext servletContext = httpRequest.getSession()
                    .getServletContext();
            webApplicationContext = RequestContextUtils
                    .getWebApplicationContext(httpRequest, servletContext);
            if (webApplicationContext == null) {
                throw new IllegalStateException(
                        "Spring Web Appliction Context is not ready");
            }
        }

        return webApplicationContext.getBean(beanName);
    }
}

subclass-Page just invoke getBean("myService") to obtain Spring
managed bean. It likes what ActionSupport does when integrating Struts with Spring,
and it works great (and easily) for our past Struts+Spring application.

Since programming style of wicket Page often consist various inner class or static inner class,
it would be helpful to declare webApplicationContext as  "static". WebApplicationContext is a
 "singleton" through the whole applicaiton life, so I guess this may work... but I still some
concern needs your help:

Does this violating any contract of wicket? 
Is there any potential thread or clustering issues ?


--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to