title: How to keep a bean alive for the through session accessible from filter and EJB
body: <p>I am trying to set a property to a bean <code>ModelBean</code> in a Filter and access this property in a JSF controller <code>IndexController</code>.</p>
  
  <p>The ModelBean is annotated <code>@SessionScoped</code> and it is used in the filter and controller with <code>@Inject</code>. The problem is that two separate instances are created and I cannot access the property that I set in filter.</p>
  
  <p>What would be the best way to keep the bean alive throughout the session? Or maybe there is a better method to pass data from the filter? </p>
  
  <pre><code>@SessionScoped
  public class ModelBean{
      private String deviceId;
  
      public ModelBean() {
          super();
      }
  
      public String getDeviceId() {
          return deviceId;
      }
  
      public void setDeviceId(String deviceId) {
          this.deviceId = deviceId;
      }
  }
  </code></pre>
  
  <pre><code>@Provider
  public class AuthRequestFilter implements Filter {
  
      @Inject
      ModelBean model;
  
  
      @Override
      public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws
              IOException, ServletException {
  
          // the device id is set just fine
          model.setDeviceId(deviceId);
          filterChain.doFilter(servletRequest, servletResponse);
          return;
      }
  }
  </code></pre>
  
  <pre><code>@Named(value = "indexController")
  public class IndexController {
  
      @Inject
      ModelBean model;
  
      // the method **is* called from the xhtml
      public String justAnExample() {
          // this is the problem, the deviceId is null=&gt;
          return model.getDeviceId();
      }
  }
  </code></pre>