Question

I have tried code given by BalusC from link JSF 2.0 File upload but i am getting below error. It seems the file selected is not getting passed to UplaodFile object or the submit method is not getting called.

Error after clicking the submit button:

javax.faces.el.EvaluationException: java.lang.NullPointerException at 
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) at 
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at 
javax.faces.component.UICommand.broadcast(UICommand.java:315) at 
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at 
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at 
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at 
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at 
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at 
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at 
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at 
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at 
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at 
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at 
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at 
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at 
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at 
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at 
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at 
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at 
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at 
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at 
com.sun.grizzly.ContextTask.run(ContextTask.java:71) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at 
java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NullPointerException at 
suraj.Bean.submit(Bean.java:22) 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:597) at 
com.sun.el.parser.AstValue.invoke(AstValue.java:254) at 
com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) at 
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at 
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) ... 32 more
------------------------------------------------------------------------

Please advice and how to upload the file in HTTP server once the object is saved in UploadFile object.

Configuration used: tried code with both Netbeans and Eclipse(with Tomcat 6.0) JSF 2.0

Was it helpful?

Solution

You did at least not properly register the ExtensionsFilter based on the instructions. This filter is responsible for parsing the uploaded filter, however it is completely missing in the stack trace. I'd expect to see it somewhere close before FacesServlet#service() like so:

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:XXX)
...
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:XXX)

Perhaps you need to read the instructions text as well instead of blindly copypasting the code? It has to be mapped on the exact <servlet-name> of the FacesServlet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top