aspose file tools*
The moose likes JSF and the fly likes How to get the browsed file path into controller bean using JSF icefaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get the browsed file path into controller bean using JSF icefaces" Watch "How to get the browsed file path into controller bean using JSF icefaces" New topic
Author

How to get the browsed file path into controller bean using JSF icefaces

lee chan
Greenhorn

Joined: Jun 14, 2011
Posts: 15
Hi All,

I've a requirement as,

1) Need to browse a file from my local system/machine
2) Path of the file from which I browsed need to be stored in a variable in controllerbean.

This thing I've done as below,

1)...
filePathAccess.jsp
<ice:inputFile id="inputFileName" width="600" autoUpload="true" value="#{fileAccessDataBean.inputFileName}"
actionListener="#{fileAccessControllerBean.browse}"/>

2)...
FileAccessDataBean.java
/** variable to hold inputFileName. */
private String inputFileName;

/**
* @return the inputFileName
*/
public String getInputFileName() {
return inputFileName;
}

/**
* @param inputFileName the inputFileName to set
*/
public void setInputFileName(String inputFileName) {
this.inputFileName = inputFileName;
}

FileAccessControllerBean.java
public class FileAccessControllerBean {

/** latest file uploaded by client. */
private FileInfo currentFile;

FileAccessDataBean fileAccessDataBean = new FileAccessDataBean();

/**
* This method is for gettingsetting browse.
* @param event ActionEvent
*/
public void browse(ActionEvent event) {
InputFile inputFile = (InputFile) event.getSource();
String filePath = null;

LOG.debug("XXX Getting File Info into currentFile..." + inputFile);

currentFile = inputFile.getFileInfo();

LOG.info("XXX current File Name... " + currentFile.getFileName());
filePath = inputFile.getFileInfo().getPhysicalPath();
LOG.info("XXX physical path... " + filePath);

fileAccessDataBean.setInputFileName(inputFile.getFileInfo().getPhysicalPath());

File file = currentFile.getFile();
filePath = file.getAbsolutePath();
LOG.info("XXX absolute path.. " + filePath);
}
}

=========================================================

Browsed file location: C:\Documents and Settings\personInfo.xml

XXX Getting File Info into currentFile... personInfo.xml
XXX current File Name... personInfo.xml
XXX physical path File Name... U:\glassfish.frontend\domains\..\..\personInfo.xml
XXX absolute path.. U:\glassfish.frontend\domains\..\..\personInfo.xml

in the above two logs I'm getting serverpath of the file.. But I want exact browsed path that is C:\Documents and Settings\personInfo.xml

how can I get the path? Is there any other way to browse the file and get the path of the file into controllerbean?

PLEASE HELP ME OUT It's very urgent requirement for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the browsed file path into controller bean using JSF icefaces