我在我的项目中创建了一个上传功能,它一直在运行,直到我为我的项目添加了漂亮的脸。
我尝试调试fileuploadListener方法并且没有调用它。
我正在使用glassfish 4.1.1,jsf-api 2.1.7和Primefaces 5.3。
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
10
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto|native|commons</param-value>
</context-param>
<filter>
<filter-name>primeUploadFilter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>primeUploadFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<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>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
</web-app>
然后我的方法来自bean:
public void doUpload(FileUploadEvent fileUploadEvent) {
UploadedFile uploadedFile = fileUploadEvent.getFile();
String fileNameUploaded = uploadedFile.getFileName();
long fileSizeUploaded = uploadedFile.getSize();
String infoAboutFile = "<br/> Arquivo recebido: <b>" + fileNameUploaded + "</b><br/>" + "Tamanho do Arquivo: <b>" + fileSizeUploaded + "</b>";
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage("Sucesso", infoAboutFile));
anexo = new Anexo();
anexo.setNm_anexo(uploadedFile.getFileName());
anexo.setDh_upload(new Date());
anexo.setAnexo(uploadedFile.getContents());
tarefa.getAnexos().add(anexo);
tarefa.setTem_anexo("true");
}
还有我的前端:
<p:tab id="anexos" title="Anexos">
<h:panelGrid columns="2" id="tbanexos">
<h:outputText value="Anexar Aquivos"/>
<p:fileUpload sizeLimit="104857600" auto="true" widgetVar="uploader" label="Procurar..." fileUploadListener="#{TarefaMB.doUpload}"
update="tableanexos" multiple="false"/>
<h:outputText/>
</h:panelGrid>
<p:dataTable id="tableanexos" var="a" value="#{TarefaMB.anexos}" emptyMessage="Nenhum arquivo anexado a tarefa.">
<p:column headerText="Nome Arquivo">
<h:outputText value="#{a.nm_anexo}"/>
</p:column>
<p:column styleClass="col-data" headerText="Data do Upload">
<h:outputText value="#{a.dh_upload}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
</h:outputText>
</p:column>
<p:column headerText="Ações">
<p:commandButton value="Download" icon="ui-icon-arrowthickstop-1-s" ajax="false">
<f:setPropertyActionListener target="#{TarefaMB.anexo}" value="#{a}"/>
<p:fileDownload value="#{TarefaMB.doDownload()}"/>
</p:commandButton>
<p:commandButton value="Remover" icon="ui-icon-close"/>
</p:column>
</p:dataTable>
</p:tab>
当我选择文件时没有任何反应。这开始于我把漂亮的面孔放入我的项目中。
我已经尝试将de context.xml放在我的WEB-INF中,但是没有用:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true">
</Context>