使用p:fileUploaded时,fileuploaded始终为null

时间:2015-02-19 22:05:34

标签: jsf primefaces jsf-2.2

从primefaces5.0使用fileUpload时,上传的文件始终为空。

观点:

<h:form enctype="multipart/form-data"  style="text-align:center;">
    <p:fileUpload value="#{noteController.fileName}" mode="simple" skinSimple="true" />
    <p:commandButton  class="btn btn-success" value="Upload file" ajax="false"  actionListener="#{noteController.upload}" />
</h:form>

ManagedBean:

@ManagedBean( name = "noteController")
@ApplicationScoped
public class NoteController {
    private UploadedFile fileName;
    public String upload(){
        if(fileName != null) {
           return "success";
        }
        return "error";
    }
public UploadedFile getFileName() {
    return fileName;
}

public void setFileName(UploadedFile fileName) {
    this.fileName = fileName;
}
}

在web.xml中,我添加了这个:

<context-param>
    <param-name>primefaces.UPLOADER</param-name>
    <param-value>commons</param-value>
</context-param>

<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>

结果:fileName始终为null,并且视图未重定向到错误视图。触发动作上传时,视图保持在同一页面。

1 个答案:

答案 0 :(得分:0)

删除skinSimple =“true”,这对我有用。 无论如何,仍然试图找到原因...