使用 p:fileUpload 尝试上传文件时,我收到了错误消息。 我尝试了maven clean和maven install for update dependeces。 我多次更改了web.xml。我相信问题是与我的anotation的关系,我正在使用@Autowired(Spring),但是我改变了它并没有工作。 我如何解决这个问题?
我正在使用: Primefaces 6.0 , Java 8, Spring Data, Spring MVC
我的网站xml:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<url-pattern>*.jsf</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
JSF:
<p:fileUpload id="fileDescAto" auto="true" multiple="false"
invalidFileMessage="Tipo de Arquivo Inválido:"
disabled="#{not empty searchDocumentoBean.descAtoArquivoFileName}"
update="messagesDialog @this panelGroupFileDescription"
allowTypes="/(\.|\/)(pdf)$/" sizeLimit="10485760"
invalidSizeMessage="Tamanho de arquivo excedido (10MB):"
fileUploadListener="#{searchDocumentoBean.adicionaArquivoUpload}"
label="Escolher Arquivo..." mode="advanced" />
豆:
public void adicionaArquivoUpload(FileUploadEvent ev) {
String[] name = ev.getFile().getFileName().split("\\\\");
descAtoArquivo = ev.getFile().getContents();
descAtoArquivoFileName = name[name.length-1];
}
public void removeArquivoUpload() {
descAtoArquivo = null;
descAtoArquivoFileName = null;
}// GET AND SET OMITED
头部注释我的bean:
@Component
@Scope("view")
@ManagedBean(name = "searchDocumentoBean")
@URLMappings(mappings = {
@URLMapping(id ="searchDocumento", pattern = "/searchDocumento", viewId = "/resources/pages/documento/searchDocumento.jsf")
})
我尝试使用文件上传时的错误控制
处理RENDER_RESPONSE 6时获得的javax.faces.event.AbortProcessingException错误:UIComponent-ClientId
08:43:55,231 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-/0.0.0.0:8080-2) Error Rendering View[/resources/pages/documento/searchDocumento.xhtml]: javax.faces.event.AbortProcessingException: java.lang.NullPointerException
at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:303) [primefaces-6.0.jar:6.0]
at org.primefaces.context.PrimePartialResponseWriter.startUpdate(PrimePartialResponseWriter.java:142) [primefaces-6.0.jar:6.0]
Caused by: java.lang.NullPointerException
at org.primefaces.util.ResourceUtils.filterStylesheets(ResourceUtils.java:96) [primefaces-6.0.jar:6.0]
at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:287) [primefaces-6.0.jar:6.0]
... 49 more
08:43:55,246 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-/0.0.0.0:8080-2) JSF1073: javax.faces.event.AbortProcessingException obtido durante o processamento de RENDER_RESPONSE 6: UIComponent-ClientId=, Message=java.lang.NullPointerException
08:43:55,240 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-/0.0.0.0:8080-5) Error Rendering View[/resources/pages/documento/searchDocumento.xhtml]: javax.faces.event.AbortProcessingException: java.lang.NullPointerException
更新27/09/2017 我发现错误: JBWEB000281:Servlet映射指定一个未知的Servlet名称Faces Servlet'
我的web.xml中出现错误?
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>openEntityManager</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
答案 0 :(得分:0)
这解决了我的问题:
Listener method in p:fileUpload is never invoked in primefaces
除此之外。 我需要指定Faces Servlet的位置:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<强> javax.faces.webapp.FacesServlet 强>
我需要especify资源primefaces取决于fileupload工作正常&gt;
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
在某些版本的primefaces中,没有必要指定此配置。我目前正在使用6.0版,它认为在web.xml中不需要此规范,因为它是一个较新的版本,但它是必要的。