I am trying to implement a File Uploader until the PF 3.X FileUpload becomes stable. I am leveraging an IFrame inside a composite component to perform the file upload. Essentially this...
<p:layout position="center">
<p:outputPanel layout="block">
<iframe src="excel_uploader.xhtml" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" width="100%" height="300">
<p style="font-size:12px">Your browser does not support iframes.</p>
</iframe>
</p:outputPanel>
</p:layout>
Note that the included file, excel_uploader.xhtml, is...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:nova="http://novartis.net/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link href="./resources/app/css/master.css" rel="stylesheet" type="text/css" />
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<div style="width:750px">
<p:messages />
<div style="font-size:12px;padding-top:15px">
<nova:inputFile id="file" value="#{excelUploader.file}" validator="excelFileValidator" />
<p:commandButton ajax="false" actionListener="#{excelUploader.onUploadExcelFile}" value="Attach Smart Sheet" styleClass="input_datagrid_button" style="color:#ffffff;margin-left:0" />
</div>
<div style="font-size:12px;padding-top:10px">
Smart Sheet: <h:outputText styleClass="app_input_lbl_bold" value="#{excelUploader.fileName}" />
</div>
<h:inputHidden id="upload_file_name" value="#{excelUploader.fileName}" />
</div>
</h:form>
</h:body>
</html>
And request-scoped backing bean, ExcelUploader.java, is...
@ManagedBean
@RequestScoped
public class ExcelUploader {
// <editor-fold desc="Class-Level Variables">
private File _File;
private String _FileName;
// </editor-fold>
// <editor-fold desc="Properties">
public String getFileName() {
return _FileName;
}
public void setFileName(String value) {}
public File getFile() {
return _File;
}
public void setFile(File file) {
this._File = file;
}
// </editor-fold>
// <editor-fold desc="Methods">
public void onUploadExcelFile() {
if (this._File != null && this._File.length() > 0)
this._FileName = this._File.getName();
}
// </editor-fold>
}
When I navigate to the composite component, which is one in a series of wizard-like components, I get the following error:
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:288)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at Novartis.OTM.Http.MultipartFilter.doFilter(MultipartFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(Pro开发者_JAVA技巧cessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Can someone elaborate as to why the Faces Servlet is throwing the nullException at the RestoreViewPhase event? I am using Primefaces + Mojarra 2.0.3. Is this a bug in Mojarra? Thank you!
As per issue 1764, this has been fixed in Mojarra 2.1.1. Upgrade accordingly.
精彩评论