我正在尝试实现一个文件上传程序,直到PF3.X文件上传变得稳定。我正在利用复合组件中的IFrame来执行文件上传。本质上这。。。
<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>
请注意,包含的文件excel_uploloader.html是…
<?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>
请求范围的backingbean ExcelUploader.java是…
@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>
}
当我导航到复合组件时,它是一系列类似向导的组件中的一个,我会得到以下错误:
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(ProcessorTask.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)
有人能详细说明为什么FacesServlet在RestoreViewPhase事件中抛出nullException吗?我使用的是Primefaces+Mojarra 2.0.3。这是莫哈拉的一只虫子吗?非常感谢。
根据第1764期,这已在Mojarra 2.1.1中修复。相应升级。