1 Reply Latest reply on Aug 22, 2007 5:44 PM by Pete Muir

    Success configuring generic filters in SEAM?

    Greg Kasi Newbie

      All,
      I am using SEAM 1.2.1 and have had extensive trouble adding custom filters to SEAM.

      What is the correct way to add filters to SEAM? Is it best to use standard servlet filters? If so, how do I configure the servlet filters to have access to SEAM Objects, or enable those objects to be injected?

      If it is best to have my filters implement seam's AbstractFilter Class, how do I go about configuring that AbstractFilter with url-patterns, and various other initialization data?

      Any help will be greatly appreciated.

      ~Greg.

        • 1. Re: Success configuring generic filters in SEAM?
          Pete Muir Master

          This is much easier in Seam2, if you can use it...

          @Scope(APPLICATION)
          @Name("myFilter")
          @BypassInterceptors
          @Filter(within="org.jboss.seam.web.ajax4jsfFilter")
          public class MyFilter extends AbstractFilter {
          
           public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
           new ContextualHttpServletRequest( (HttpServletRequest) request ) {
           public void process() throws ServletException, IOException
           {
           // Do your work
           }
           }.run();
           }
          }


          If you are stuck on Seam 1.2, then you don't havve @Filter and you don't have ContextualHttpServletRequest, so mark your filter with @Name and @Startup, and do the Lifecycle setup and teardown yourself (look at filters in org.jboss.seam.web for how to do this).

          You can configure it using components.xml as usual (just add getters and setters).