PrimeFaces + FileUpload

1 resposta
M

Qual é a mágica para fazer o PrimaFaces fazer funcionar o FileUplooad?

Baixei os jars:

commons-fileupload-1.1.jar
commons-io-1.4.jar
primefaces-2.2.M1.jar

Fui em Propriedades do projetos e adicioneis as bibliotecas.
Uso NetBenas 6.9 + GlassFish 3 + JSF 2.0

Tem que ter JavaScript? Ou não?
Detalhe ele nem filtra os valores:

Estão assim os fontes:

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>
    <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>
    <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>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

Bean

package mtsys.file;

import javax.faces.bean.ManagedBean;
import org.primefaces.event.FileUploadEvent;

@ManagedBean
public class FileUploadController {
 private String nomeArquivoSelecionado;

 public String getNomeArquivoSelecionado() {
 return nomeArquivoSelecionado;
 }

 public void setNomeArquivoSelecionado(String nomeArquivoSelecionado) {
 this.nomeArquivoSelecionado = nomeArquivoSelecionado;
 }

 public void fileUploadAction(FileUploadEvent event) {
setNomeArquivoSelecionado(event.getFile().getFileName());
 }
}

index.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="base.xhtml">
        <ui:define name="content">
            <h:form>              
                <p:fileUpload
                    auto="false"
                    label="Selecionar..."
                    allowTypes="*.gif,*.png,*.jpg"
                    multiple="false"
                    description="Imagem"
                    fileUploadListener="#{fileUploadController.fileUploadAction}"
                    update="idarquivo"/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>

1 Resposta

G

Usa o jar do primefaces-2.1 pois o 2.2M1 não sei pq não tá funcionando.
Abraço.

Criado 13 de setembro de 2010
Ultima resposta 21 de set. de 2010
Respostas 1
Participantes 2