how to fetch file path while file uploading
vasukihn Jun 16, 2010 7:54 AMHi All,
I am parsing the spreadsheet in my application. I want to get the file path of the spreadsheet which i can send as an parameter to my parsing function.
I have created a UploadFile.java and uploadfile.xhtml. I will attach my code here.
package org.domain.user.session; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.AutoCreate; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Scope; import org.jboss.seam.log.Log; import org.jboss.seam.international.StatusMessages; import org.hibernate.validator.Length; import turnup.Util; @Name("uploadFile") public class UploadFile { @Logger private Log log; @In StatusMessages statusMessages; private String value; public void uploadFile() { // implement your business logic here log.info("uploadFile.uploadFile() action called with: #{uploadFile.value}"); statusMessages.add("uploadFile #{uploadFile.value}"); String v2 = value; System.out.println(v2); Util.processFile(v2); } // add additional action methods @Length(max = 10000) public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
xhtml file
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml"> <ui:define name="body"> <h:form id="uploadFileForm" enctype="multipart/form-data"> <rich:panel> <f:facet name="header">UploadFile</f:facet> <s:decorate id="value" template="layout/edit.xhtml"> <ui:define name="label">Browse the file</ui:define> <s:fileUpload id="file" accept="application/*" fileName="#{uploadFile.value}"></s:fileUpload> </s:decorate> <div style="clear:both"/> </rich:panel> <div class="actionButtons"> <h:commandButton id="uploadFile" value="UploadFile" action="#{uploadFile.uploadFile}"/> </div> </h:form> </ui:define> </ui:composition>
I dont how to pass the file path which i get when browsing the file to my processfile method.
I just need only the filepath from front-end to action file(UploadFile.java).
Please help me in correcting my code.
Thanks
Vaasuki.