-1

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

Community
  • 1
  • 1
SJUmbarkar
  • 3
  • 1
  • 5
  • The submit method is definitely invoked. Even more, the stacktrace shows that the `NullPointerException` is coming from the submit method itself. Apparently you didn't carefully follow the steps, descriptions and examples. Hard to tell based on the information provided so far. – BalusC Aug 17 '13 at 14:56
  • Thanks BalusC for the response. When I double checked my Project configuration, I am using JSF 2.0 with servlet 2.5[Tomcat 6.0], should I upgrade the project to use servlet 3.0 or can you help you with code for JSF 2.0 and servlet 2.5, Thanks in advance.. – SJUmbarkar Aug 18 '13 at 13:18
  • @BalusC I tried the same code(modified little bit) with netBeans 7.1.2 app having Glassfish server 3.1.2, [jsf 2.0 project using servlet container] but still I am getting the Null Pointer excpetion.CHANGES MADE IN THE FACES-CONFIG FILE -->have added navigation from upload to Welcome page ,CHANGES MADE IN THE BEAN.JAVA -->submit method will return as a string, added Println() methods. After debugging the code I found out it is failing at "String fileName = FilenameUtils.getName(uploadedFile.getName());" line.Please let me what more details should i provide which can identify my mistake... – SJUmbarkar Aug 19 '13 at 12:11
  • So far it look like you didn't properly set form's enctype, or haven't properly registered the filter. Sorry, I can't help you much as the instructions are already complete and you didn't show what exactly you did different. – BalusC Aug 19 '13 at 12:23
  • Code change in Bean.java--> public String submit() throws IOException { System.out.println("initial point"); String fileName = FilenameUtils.getName(uploadedFile.getName()); System.out.println("File name is "+ fileName); String contentType = uploadedFile.getContentType();System.out.println("File contentTypeis "+ contentType);byte[] bytes = uploadedFile.getBytes(); ... return "success"; } – SJUmbarkar Aug 19 '13 at 12:54
  • Code change in faces-config.xhtml Upload/upload.xhtml success/Welcome.xhtml (Above 2 are the only code changes) – SJUmbarkar Aug 19 '13 at 12:59
  • Those are not relevant. You should tell what you did different from the instructions as to the file upload part. In any way, I think I see the cause. The `ExtensionsFilter` is completely missing in the stack trace. I posted an answer. – BalusC Aug 19 '13 at 12:59
  • Error from Glass fish: INFO: initial point WARNING: #{bean.submit}: java.lang.NullPointerException javax.faces.FacesException: #{bean.submit}: java.lang.NullPointerException at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) 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)......and – SJUmbarkar Aug 19 '13 at 13:03
  • **bold*contd..... WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception java.lang.NullPointerException at com.example.Bean.submit(Bean.java:24) 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) Please find additional details of log details and changes in files, hope it helps. – SJUmbarkar Aug 19 '13 at 13:07
  • Why do you keep posting code in comments? Just edit and update the question if you think you need to. Have you read my comment and answer? – BalusC Aug 19 '13 at 13:12

1 Answers1

0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Actually i am totally new to JSF and not getting good JSF tutorials on net for reference. I am sorry but i didnt get you! Should i add the same code for face-config also as web.xml or what exactly should be added in faces-config.xml file. – SJUmbarkar Aug 19 '13 at 13:51
  • Carefully read the *"Configure the Tomahawk extensions filter"* section of the instruction set in the link you found. Every word. – BalusC Aug 19 '13 at 14:00
  • Please edit and update the question with the current stack trace. – BalusC Aug 19 '13 at 14:11
  • I have added the servlet code given by you in web.xml and was able to retrieve the file details in println() statement and move to Welcome.html successfully.Sorry for that and thanks a Ton for all the help! For writing the file to HTTP server can you help me with some code or links which i can refer! – SJUmbarkar Aug 19 '13 at 14:19