1 Reply Latest reply on Mar 2, 2011 6:06 PM by Tim Evers

    Injection not workin in filter class

    lucasmonsterrocha Newbie

      I have the class above and i could'nt inject certificadoAction or validarCertificadoDigital using @In(create true) it's comming null.

      public class FiltroCertificado extends SeamFilter {

              @In(create true)
              private ValidarCertificadoDigitalAction certificadoAction;
              @In(create true)
              private ValidarCertificadoDigital validarCertificadoDigital;
              public void doFilter(ServletRequest request, ServletResponse response,
                              FilterChain chain) throws IOException, ServletException {
                      System.out.println(chamou filtro);

                      super.doFilter(request, response, chain);

        • 1. Re: Injection not workin in filter class
          Tim Evers Master

          Well, your FiltroCertificado isn't a Seam bean so no Bijection is going to take place.

          You need to add the @Name annotation to the bean as well.

          Take a look at the source code for any one of Seams built in filters.

          They all start pretty much like this:

          @Install(precedence = BUILT_IN, dependencies="org.jboss.seam.web.ajax4jsfFilterInstantiator")
          public class Ajax4jsfFilter extends AbstractFilter

          Now, obviously with the @BypassInterceptors annotation on the class the @In is still not going to work. So you have a couple of options.

          1. Remove the @BypassInterceptors annotation and let Seam do it's magic. (NOT RECOMMENDED: This will put a lot of very unnecessary overhead on your Filter and I'm not even sure it works...never tried :P).

          2. Instead of using the @In to get a reference to a Seam bean use the Component.getInstance() method.

          I'm concerned though that you might be going the wrong way about the problem. (Using a filter that is) But, without knowing what those other Seam beans are for it is a bit hard. Filters are generally APPLICATION scoped so you want to make sure you understand that any state you have in the Filter is for EVERYONE.