wood burning stoves 2.0*
The moose likes JSF and the fly likes How to upload file in jsf using richfaces? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to upload file in jsf using richfaces?" Watch "How to upload file in jsf using richfaces?" New topic
Author

How to upload file in jsf using richfaces?

siva prasa
Greenhorn

Joined: Feb 16, 2010
Posts: 25
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">
<hutputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
</f:facet>
</rich:fileUpload>



Santosh Kumar V
Greenhorn

Joined: Mar 17, 2010
Posts: 5


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to upload file in jsf using richfaces?
 
Similar Threads
executePhase (PROCESS_VALIDATIONS 3..) Error on h:selectItems
Jsf DropDown menu "java.util.NoSuchElementException"
Help me I am getting this Error...Exception thrown during phase execution:
Error: Dynamic Menu + Richfaces + A4j
NoClassDefFoundError: Could not initialize class