开发者

Richfaces fileupload Error

I have tries to upload the file using rich:fileupload componenet.When i tried to upload the file,it arise the error, The error is

Aug 24, 2011 9:41:19 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
        at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:140)
        at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
        at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:764)
        at javax.faces.component.UIInput.decode(UIInput.java:719)
        at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1006)
        at javax.faces.component.UIInput.processDecodes(UIInput.java:633)
        at javax.faces.component.UIForm.processDecodes(UIForm.java:203)
        at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
        at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
        at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
        at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
        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:365)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
        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:127)
        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:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoE开发者_运维问答ndpoint.java:489)
        at java.lang.Thread.run(Thread.java:679)

Please help me to resolve this issue.


The stacktrace hints that you're using both RichFaces 3.3 and Tomahawk 1.x. Both component libraries offers file upload components and extracts uploaded files from the request body using a special Filter. The stacktrace shows that the Tomahawk one is parsing the request body before the RichFaces one.

at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
...
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)

Once a request body is been parsed, it cannot be parsed anymore. RichFaces is therefore unable to extract the uploaded file from the request body. The NullPointerException which you're facing is just the unforeseen consequence of this (the RichFaces guys should have thrown a more clear exception instead, something like an IllegalStateException with the message "Uploaded file is missing in the request body" or like, but ala).

If you want to use RichFaces file upload functionality, then you've really got to remove the Tomahawk's ExtensionsFilter from web.xml. You'll only miss the <t:inputFileUpload> functionality and some minor features (scripts/stylesheets) of specific look'n'feel components. Other Tomahawk components should remain working fine.


RichFaces 3.3 file upload is working follow this step.

Add this in your page:

<rich:fileUpload id="fileupload" addControlLabel="Browse" required="true"
fileUploadListener="#{ demoForm.listener}" acceptedTypes="xml"
ontyperejected="alert('Only xml files are accepted');"
maxFilesQuantity="1" listHeight="57px" listWidth="100%" disabled="#{demoForm.disabled}" >
<a4j:support event="onclear" action="#{ demoForm.clearUploadData}" reRender="fileupload" />
</rich:fileUpload>

FormBean:

/**
*
* @param event
* @throws Exception
*/
public void listener(UploadEvent event) throws Exception{
UploadItem item = event.getUploadItem();
FileUpload file = new FileUpload();
file.setLength(item.getData().length);
file.setFile(item.getData());
file.setName(item.getFileName());
files.add(file);
}


/**
 * 
 * @return
 */public String clearUploadData() {
files.clear();
setUploadsAvailable(1);
return null;
}

Add this content in web.xml

<!-- Richfaces  fileupload-->
    <filter>
        <!-- Parameters used by rich file upload -->
        <init-param>
            <param-name>createTempFiles</param-name>
            <param-value>false</param-value>
        </init-param>
        <!-- configurable property of rich:fileUpload to set maximum allowed file size, currently set to  200MB -->
        <init-param>
            <param-name>maxRequestSize</param-name>
            <param-value>209715200</param-value>
        </init-param>
        <init-param>
            <param-name>forceparser</param-name>
            <param-value>false</param-value>
        </init-param>
    </filter>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜