1 Reply Latest reply on Apr 25, 2013 8:38 AM by vata2999

    Integrating Seam in Vaadin application problem

    timkepp

      Hi all

      I'm a newbie in Seam and I'm trying to integrate Seam in a Vaadin application.

      I'm trying to get access to the application context in my UI class but Contexts.getApplicationContext() returns NULL.

      I don't know what I'm doing wrong. Could anybody help me?

       

      Thx

      Tim

       

       

      MyVaadinApplication.java:

      package com.me.ui.application;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.contexts.Contexts;
      
      import com.me.presenter.TestPresenter;
      import com.vaadin.server.VaadinRequest;
      import com.vaadin.ui.Label;
      import com.vaadin.ui.UI;
      import com.vaadin.ui.VerticalLayout;
      
      @Scope (ScopeType.APPLICATION)
      @Name("applicationBean")
      public class MyVaadinApplication extends UI {
      
        @Override
        public void init(VaadinRequest request) {
          VerticalLayout layout = new VerticalLayout();
          layout.addComponent(new Label("some stuff"));
          setContent(layout);
      
          TestPresenter presenter = (TestPresenter) Contexts.getApplicationContext().get(TestPresenter.class); //--> NPE
        }
      
        @Create
        public void createPresenter() {
          //--> this is never reached
          TestPresenter presenter = (TestPresenter) Contexts.getApplicationContext().get(TestPresenter.class);
        }
      }
      

       

      SeamApplicationServlet.java:

      package com.me.ui.application;
      
      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      
      import com.vaadin.server.DeploymentConfiguration;
      import com.vaadin.server.ServiceException;
      import com.vaadin.server.SessionInitEvent;
      import com.vaadin.server.SessionInitListener;
      import com.vaadin.server.UIClassSelectionEvent;
      import com.vaadin.server.UIProvider;
      import com.vaadin.server.VaadinServlet;
      import com.vaadin.server.VaadinServletService;
      import com.vaadin.ui.UI;
      
      public class SeamApplicationServlet extends VaadinServlet {
        private String applicationBean;
        private static final String APPLICATION_BEAN_NAME_PARAM = "applicationBean";
      
        @Override
        public void init(ServletConfig servletConfig) throws ServletException {
          super.init(servletConfig);
      
          applicationBean = servletConfig.getInitParameter(APPLICATION_BEAN_NAME_PARAM);
      
          if(applicationBean == null) {
            throw new ServletException("ApplicationBean not specified in servlet parameters");
          }
        }
      
        @Override
        protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) {
          VaadinServletService service = super.createServletService(deploymentConfiguration);
          service.addSessionInitListener(new SessionInitListener() {
               @Override
              public void sessionInit(SessionInitEvent event) throws ServiceException {
                event.getSession().addUIProvider(new SeamProvider());
              }
            });
      
          return service;
        }
      
        private class SeamProvider extends UIProvider {
          @Override
          public Class<? extends UI> getUIClass(UIClassSelectionEvent uiClassSelectionEvent) {
            return MyVaadinApplication.class;
          }
        }
      }
      
      

       

      web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
          <display-name>Vaadin Web Application</display-name>
      
          <context-param>
              <description>Vaadin production mode</description>
              <param-name>productionMode</param-name>
              <param-value>false</param-value>
          </context-param>
      
          <listener>
              <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
          </listener>
      
          <filter>
              <filter-name>Seam Filter</filter-name>
              <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
          </filter>
      
           <filter-mapping>
              <filter-name>Seam Filter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
      
          <servlet>
              <servlet-name>Vaadin Application Servlet</servlet-name>
              <servlet-class>com.me.ui.application.SeamApplicationServlet</servlet-class>
              <init-param>
                  <description>Vaadin application class to start</description>
                  <param-name>applicationBean</param-name>
                  <param-value>com.me.ui.application.MyVaadinApplication</param-value>
              </init-param>
          <load-on-startup>1</load-on-startup>
          </servlet>
      
          <servlet-mapping>
              <servlet-name>Vaadin Application Servlet</servlet-name>
              <url-pattern>/*</url-pattern>
          </servlet-mapping>
      </web-app>
      

       

      component.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.org/schema/seam/components"
                xmlns:core="http://jboss.org/schema/seam/core"
                xmlns:web="http://jboss.com/products/seam/web"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://jboss.org/schema/seam/core http://jboss.org/schema/seam/core-2.3.xsd
                        http://jboss.org/schema/seam/bpm http://jboss.org/schema/seam/bpm-2.3.xsd
                        http://jboss.org/schema/seam/components http://jboss.org/schema/seam/components-2.3.xsd">
      
        <component name="org.jboss.seam.core.init">
          <property name="debug">true</property>
        </component>
      
        <web:context-filter url-pattern="/MyVaadinApplication/*"/>
      
      </components>