This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

How to upload file in jsf using richfaces?  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting null pointer exception when i am uploading file.I can see the selected file in richfaces file upload box.Then i click upload button it is showing null pointer exception.if any one knows setup for that with example please share with me......thanks for reading this .....

Mar 22, 2010 11:26:51 AM com.sun.faces.lifecycle.ApplyRequestValuesPhase execute
WARNING: java.lang.NullPointerException
javax.faces.FacesException: java.lang.NullPointerException
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:714)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:221)
at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:412)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:385)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:138)
at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:789)
at javax.faces.component.UIInput.decode(UIInput.java:725)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1031)
at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
at org.ajax4jsf.component.UIAjaxRegion.processDecodes(UIAjaxRegion.java:103)
at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:395)
at org.ajax4jsf.component.ContextCallbackWrapper.invokeContextCallback(ContextCallbackWrapper.java:44)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:711)
... 46 more
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
Mar 22, 2010 11:26:51 AM com.sun.faces.lifecycle.Phase doPhase
SEVERE: JSF1054: (Phase ID: APPLY_REQUEST_VALUES 2, View ID: /home/ppsMain.jsp) Exception thrown during phase execution: javax.faces.event.PhaseEven
t[source=com.sun.faces.lifecycle.LifecycleImpl@128dca6]
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-1] DEBUG com.celcom.app.bean.BlacklistBean - getSelectedBlacklist ...null
2010 Mar 22 11:26:51 [http-8080-3] ERROR org.ajax4jsf.webapp.BaseXMLFilter - Exception in the filter chain
javax.servlet.ServletException: java.lang.NullPointerException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:385)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.faces.FacesException: java.lang.NullPointerException
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:714)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:720)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:675)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:221)
at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:412)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
... 21 more
Caused by: java.lang.NullPointerException
at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:138)
at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:789)
at javax.faces.component.UIInput.decode(UIInput.java:725)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1031)
at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
at org.ajax4jsf.component.UIAjaxRegion.processDecodes(UIAjaxRegion.java:103)
at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:395)
at org.ajax4jsf.component.ContextCallbackWrapper.invokeContextCallback(ContextCallbackWrapper.java:44)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:711)
... 46 more

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Celcom-PPS</display-name>

<welcome-file-list>
<welcome-file>/home/index.jsp</welcome-file>
</welcome-file-list>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>



<!-- RichFaces Setting START -->
<!-- Plugging the "Blue Sky" skin into the project -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>

<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>

<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<filter>
<filter-name>MyFacesExtensionFilter</filter-name>
<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>MyFacesExtensionFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>MyFacesExtensionFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>

<!--
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
-->

<!-- RichFaces Setting END -->


<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>






<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>configuration-init</servlet-name>
<servlet-class>com.compudyne.application.config.SConfiguration</servlet-class>
<init-param>
<param-name>FILE_PROP</param-name>
<param-value>app-config.properties</param-value>
</init-param>
<init-param>
<param-name>FILE_LOGGER</param-name>
<param-value>log4j.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>OCSRequestServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.OCSRequestServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>SimulatorGetResponseFE</servlet-name>
<servlet-class>com.compudyne.simulater.ocs.serlvet.SimulatorGetResponseFE</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>SimulatorGetResponseBE</servlet-name>
<servlet-class>com.compudyne.simulater.ocs.serlvet.SimulatorGetResponseFE</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>MaybankResponseServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.MaybankResponseServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>TransactionReportServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.TransactionReportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>TransactionReportSummaryServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.TransactionReportSummaryServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>TransactionReportSummaryDetailServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.TransactionReportSummaryDetailServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>ExcelFormatDownloadServlet</servlet-name>
<servlet-class>com.celcom.app.servlet.ExcelFormatDownloadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- servlet mapping starts here -->

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>OCSRequestServlet</servlet-name>
<url-pattern>/servlet/OCSRequestServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MaybankResponseServlet</servlet-name>
<url-pattern>/servlet/MaybankResponseServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimulatorGetResponseFE</servlet-name>
<url-pattern>/servlet/SimulatorGetResponseFE</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimulatorGetResponseBE</servlet-name>
<url-pattern>/servlet/SimulatorGetResponseBE</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>TransactionReportServlet</servlet-name>
<url-pattern>/servlet/TransactionReport</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>TransactionReportSummaryServlet</servlet-name>
<url-pattern>/servlet/TransactionReportSummary</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>TransactionReportSummaryDetailServlet</servlet-name>
<url-pattern>/servlet/TransactionReportDetailSummary</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>ExcelFormatDownloadServlet</servlet-name>
<url-pattern>/servlet/ExcelFormatDownload</url-pattern>
</servlet-mapping>

<!-- servlet mapping ends here -->

<listener>
<listener-class> com.compudyne.ps.util.MySessionListener</listener-class>
</listener>

<filter>
<filter-name>SessionTimeoutFilter</filter-name>
<filter-class>com.compudyne.ps.util.SessionTimeoutFilter</filter-class>
</filter>


<filter-mapping>
<filter-name>SessionTimeoutFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
<!--Remember to use your correct URL pattern-->
</filter-mapping>


<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/home/yourSessionIsTimedOut.jsp</location>
</error-page>

<error-page>
<exception-type>org.hibernate.exception.GenericJDBCException</exception-type>
<location>/home/yourSessionIsTimedOut.jsp</location>
</error-page>

</web-app>

UploadFilebean.java

public void fileUploadListener(UploadEvent event) throws IOException {
if(event==null){
log.debug("null upload event");
return;
}
UploadItem item = event.getUploadItem();

String name = "unnamed_attachment";
byte[] data = item.getData();

if (item.isTempFile()) {
name = item.getFileName();
data = item.getData();
File file = item.getFile();
log.debug(
"uploaded "+name+
" - length= "+( (data==null)?0:data.length) +
" tmpFile="+file.getAbsoluteFile()
);
}

}

jsp page

<rich:fileUpload fileUploadListener="#{fileUploadBean.fileUploadListener}"
uploadData = "#{fileUploadBean.data}"
id="upload"
acceptedTypes="xls" >
<a4j:support event="onuploadcomplete" reRender="info" />
<f:facet name="newname">
<h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
</f:facet>
</rich:fileUpload>



 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Files can be uploaded automatically by means of the "immediateUpload" attribute. If the value of this attribute is "true" files are uploaded automatically once they have been added into the list.



the "srcFile" will now hold the uploaded file.

Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!