我正在使用PrimeFaces 3.1.2,NetBeans 7.2,JSF 2.1和GlassFish 3.1.2.
我正在使用我从http://www.primefaces.org/showcase/ui/fileUploadAuto.jsf 和http://www.primefaces.org/showcase/ui/fileDownload.jsf获得的实际代码.
当我运行文件上传代码时,它根本不起作用.文件未上传,未显示成功消息.但是,如果文件大小超过上述大小,则会显示文件大小过大的消息.
这是我的观点:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
update="messages"
auto="true"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:growl id="messages" showDetail="true"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的支持bean:
package com;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.FileUploadEvent;
@ManagedBean
@SessionScoped
public class FileUploadController {
public void handleFileUpload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
Run Code Online (Sandbox Code Playgroud)
它与PrimeFaces展示页面中的代码基本相同.
与文件下载代码类似; 当我点击下载时没有任何反应.弹出窗口打开和关闭,然后才能注意到它.我有get资源流中提到的图像文件(对于下载部分),但我不知道是什么问题.代码也与PrimeFaces展示页面中的代码基本相同.
我没有在Netbeans的Glassfish下看到任何日志或错误.如果有必要,我也不知道如何启用日志记录.
您需要的第一件事是向您的应用程序添加一些库.事实上,PrimeFaces文件上传依赖于Apache commons-file-upload和commons-io库.因此下载它们并将它们添加到WEB-INF/lib路径:
你可以从以下链接下载它.
http://commons.apache.org/fileupload/
此外,您必须将其配置为web.xml
<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>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>C:\etc</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
此外,如果要以编程方式设置更改上载文件的目标,请查看:
| 归档时间: |
|
| 查看次数: |
13884 次 |
| 最近记录: |