I use dhtmlxvault in my JSF1.2 project,which can not upload successfully,now I will describe my code next,please help me ,to solve it.my project use Facelet+JSF1.2+seam+jpa;
so please see my testDhtmlxVault.xhtml:
<script language="JavaScript" type="text/javascript">
var vault = null;
function doOnLoad(){
vault = new dhtmlXVaultObject();
vault.setImagePath("/Eppmcp/resources/dhtmlx/dhtmlxvault/imgs/");
vault.setServerHandlers("/Eppmcp/pages/common/dictionary/UploadHandler.faces", "/Eppmcp/pages/common/dictionary/GetInfoHandler.faces", "/Eppmcp/pages/common/dictionary/GetIdHandler.faces");
vault.onFileUploaded = function(file) {
alert("id:" + file.id + ",name:" + file.name + ",uploaded:" + file.uploaded + ",error:" + file.error);
};
vault.create("vault1");
vault.setFormField("customerId", "PS104");
vault.setFormField("country", "UK");
}
</script>
<style>
body{font-family:arial;font-size:12px}
h1 {cursor:pointer;font-size:16px;margin-left:10px;line-height:10px}
xmp {color:green;font-size:12px;margin:0px;font-family:courier;background-color:#e6e6fa;padding:2px}
.hdr{
background-color:lightgrey;
margin-bottom:10px;
padding-left:10px;
}
</style>
DHTMLX Vault sample
Add More Form Fields
pages.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<page view-id="/pages/common/dictionary/GetInfoHandler.xhtml" action="#{eppmcp.model.demo.test2.GetInfoHandler}">
</page>
<page view-id="/pages/common/dictionary/GetIdHandler.xhtml" action="#{eppmcp.model.demo.testbean.GetIdHandler}">
</page>
and the action code is:
@Name("eppmcp.model.demo.testbean")
public class TestBean {
public void GetIdHandler(){
System.out.print("in the method of GetIdHandler()!!!!");
HttpServletRequest request = FacesContextUtil.getRequest();
HttpServletResponse response = FacesContextUtil.getResponse();
String id = request.getSession().getId().toString();
PrintWriter out;
try {
out = response.getWriter();
out.println(id);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpSession session = FacesContextUtil.getSession();
session.removeAttribute("FileUpload.Progress."+id);
session.setAttribute("FileUpload.Progress."+id,"0");
FacesContextUtil.getFacesContext().responseComplete();
}
and the eppmcp.model.demo.testbean.Test2 .java code is:
@Name(“eppmcp.model.demo.test2”)
public class Test2 {
public void GetInfoHandler(){
System.out.print("in the method of GetInfoHandler()!!!!");
HttpServletResponse response = FacesContextUtil.getResponse();
HttpServletRequest request = FacesContextUtil.getRequest();
HttpSession session = FacesContextUtil.getSession();
PrintWriter out;
try {
out = response.getWriter();
System.out.println(session.getAttribute("FileUpload.Progress."+request.getParameter("sessionId").toString().trim()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FacesContextUtil.getFacesContext().responseComplete();
}
}
and the eppmcp.model.demo.testbean.Test1 .java code is:
@Name(“eppmcp.model.demo.test1”)
public class Test1 {
public void UploadHandler(){
System.out.print("in the method of UploadHandler()!!!!");
String uploadFolder = "c:\\upload\\";
HttpServletResponse response = FacesContextUtil.getResponse();
HttpServletRequest request = FacesContextUtil.getRequest();
HttpSession session = FacesContextUtil.getSession();
// Check that we have a file upload request
boolean isMultipart = FileUpload.isMultipartContent(request);
if (!isMultipart) {
PrintWriter out;
try {
out = response.getWriter();
out.println ("Use multipart form to upload a file!");
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String fileId = request.getParameter("sessionId").toString().trim();
// Create a new file upload handler
FileItemFactory factory = new ProgressMonitorFileItemFactory(request, fileId);
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List items;
try {
items = upload.parseRequest(request);
// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
//processFormField
}else{
//processUploadedFile
String fieldName = item.getFieldName();
String fileName = item.getName();
int i2 = fileName.lastIndexOf("\\");
if(i2>-1) fileName = fileName.substring(i2+1);
File dirs = new File(uploadFolder);
dirs.mkdirs();
File uploadedFile = new File(dirs,fileName);
item.write(uploadedFile);
session.removeAttribute("FileUpload.Progress."+fileId);
session.setAttribute("FileUpload.Progress."+fileId,"-1");
}
}
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FacesContextUtil.getFacesContext().responseComplete();
}
so the problem is when the program entered the method of UploadHandler,the size of List item is 0 and the while (iter.hasNext()) is false,so i do not know how to solve it,please help me,thanks!!