This is the 4th component of the Qfaces, Ajax way with the progress bar file upload component, I hope that every important component to upgrade a version, hehe! This version also fixes the Ajax compatibility problem under IE6. After introducing this component, you intend to introduce how to use qfaces from Define your own Ajax components, hopefully, this enhanced framework will help some people who like JSF. Later versions of the upgrade may not be so fast, or consider compatibility with facelets, and fix some of the possible errors, as well as open source plans, and then continue to maintain and add some of the more common and practical components, Pay attention to the development of JSF2.0 and so on.
Well, here's a new member of the Qfaces: FileUpload, the following is a screenshot of the use of the process, for the interface I do not have too high requirements, there is no open related properties, or simple to use as the first element, if you customize components, you can make a more cool or more fancy interface out, hehe!
The use of components is simple:
<q:fileupload process= "#{fileuploadbean.process}"/>
The following is the HTML complete code, which should be noted that the component cannot be placed inside the form because the component renders its own form label:
<f:view>
<meta http-equiv="Content-Type" content="text/html; charset=UTF- 8">
<title>FileUpload Demo</title>
<body>
<q:fileUpload process="#{FileUploadBean.process}"/>
</body>
</f:view>
Background beans as long as binding a processing method can be, simple operation processing, save the file to the local hard disk, the following is the demo in the example:
public boolean process(QFile qfile) throws Exception {
// 检查并创建用于保存上传文件的目录
File fileDir = new File("c:\\my-qfaces-upload-file");
if (!fileDir.exists()) {
fileDir.mkdirs();
}
// 创建文件对象,并将上传的文件保存到该对象.
File upfile = new File(fileDir.getAbsolutePath() + "\\" + qfile.getFilename ());
qfile.save(upfile);
return true;
}