Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
26. Mar 2008, 18:58 America/New_York | Link

Hello,

I have a servlet filter that responds to URL patterns of *.xls. I would like to be able to lookup a Seam component and invoke a method on it to generate the excel content that the filter streams out. The problem I am having is that this call is returning null:

SavedQuerySearchBean savedQuerySearchBean = (SavedQuerySearchBean) Contexts.lookupInStatefulContexts("savedQuerySearchBean");

inside my filter.

I looked at the @Filter annotation in the documentation but I don't see how to have this filter respond only to *.xls URL's.

1. Why is the Contexts.lookup...() call failing?

2. What is a good way to achieve what I am trying to do (i.e. have a servlet filter that renders binary data be able to call Seam components (EJB's))?

Thanks, Brad Smith

10 Replies:
26. Mar 2008, 19:32 America/New_York | Link

Check if the SeamContextFilter also applied to that url pattern. Also try using Component.getInstance().

Rating:  * *
29. Mar 2008, 12:00 America/New_York | Link

Override getPattern() to return "*.xls"

1) no idea, what is savedQuerySearchBean? Are you wrapping the call inside a ContextualHttpServletRequest?

2) What you are doing.

 

Read about how to report a bug.

31. Mar 2008, 21:34 America/New_York | Link

Starting with 2) What are you doing. ...

We need to be able to stream out an Excel doc created using POI when the user clicks a link on a page. The page is a JSF form and the state used to produce the Excel doc comes from the user working with the form. The form is backed by a SFSB (SESSION scope). The generated doc will be in Excel binary format - to my knowledge this isn't possible directly using Facelets (we're not generating textual csv data).

Override getPattern to return .xls

what does this mean?

Thanks, Brad

31. Mar 2008, 22:17 America/New_York | Link

Is SavedQuerySearchBean an EJB? If so, the type needs to be the @Local interface instead.

 

Kyle W. Burke
http://www.monkeyden.com

01. Apr 2008, 01:44 America/New_York | Link
Kyle Burke wrote on Mar 31, 2008 10:17 PM:
Is SavedQuerySearchBean an EJB? If so, the type needs to be the @Local interface instead.

I wish I could give negative stars for replies like this ;-)

01. Apr 2008, 02:42 America/New_York | Link
We need to be able to stream out an Excel doc created using POI when the user clicks a link on a page

Sounds like your filter plan will work. Would a servlet be more appropriate for this situation? I second Pete's suggestion about checking on the ContextualHttpServletRequest in your filter as a servlet or filter needs this to tie into the Seam context somehow.

Override getPattern to return .xls

I think Pete means override the getUrlPattern method of org.jboss.seam.web.AbstractFilter and return the pattern for which you want your new filter to be invokved (*.xls).

Rating:  * * *
01. Apr 2008, 15:25 America/New_York | Link

What is the exact set of steps I need to do to turn on a filter?

I followed section 25.1.4.8. Adding custom filters, but got the following exception:

09:06:39,663 ERROR [[/component-demo]] Exception starting filter Seam Filter
java.lang.NullPointerException
        at org.jboss.seam.servlet.SeamFilter.getSortedFilters(SeamFilter.java:131)
        at org.jboss.seam.servlet.SeamFilter.init(SeamFilter.java:93)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
        at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3722)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4367)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
        at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
        at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
        at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
        at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
        at org.jboss.web.WebModule.startModule(WebModule.java:83)
        at org.jboss.web.WebModule.startService(WebModule.java:61)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
        at $Proxy0.start(Unknown Source)
        at org.jboss.system.ServiceController.start(ServiceController.java:417)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy44.start(Unknown Source)
        at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
        at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
        at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
        at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
        at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy45.start(Unknown Source)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
        at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy9.deploy(Unknown Source)
        at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
        at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
01. Apr 2008, 16:18 America/New_York | Link

I got it - thanks for the help Pete and Mark.

The filter has this structure:

@Name("StreamExcelFilter")
@Scope(ScopeType.APPLICATION)
@Filter(within="org.jboss.seam.web.ajax4jsfFilter")
public class StreamExcelFilter extends AbstractFilter {

    @In(required = false)
    private List<EvergreenUser> targetEmployees;

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain)
        throws IOException, ServletException {

        servletResponse.setContentType("application/vnd.ms-excel");


        // generate some excel content

    }

    public String getUrlPattern() {
        return "*.xls";
    }
}

and EVERY annotation shown in the sample code MUST be used for it to work.

Thanks, Brad Smith

PS - the seam text drives me krazeee!

01. Apr 2008, 17:32 America/New_York | Link
Bradley Smith wrote on Apr 01, 2008 01:44 AM:
I wish I could give negative stars for replies like this ;-)

Believe it or not, this was recently at the root of an associate's problems. Of course not knowing you, let alone your apparently impressive credentials, it was worth asking.

 

Kyle W. Burke
http://www.monkeyden.com

01. Apr 2008, 19:32 America/New_York | Link
Kyle Burke wrote on Apr 01, 2008 05:32 PM:
Believe it or not, this was recently at the root of an associate's problems. Of course not knowing you, let alone your apparently impressive credentials, it was worth asking.

I have had many obvious blunders (with Seam, JSF, etc... pick one) before but I didn't think anything in my post suggested an issue with EJB's and EJB-annotation usage. Anyway, as you can see, I've got the filter working. I kinda like it better than the ole-fashioned filter-in-web.xml approach.