Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Uploading xls files with JSF

 
Greenhorn
Posts: 14
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All...

I have problem with JSF file uploading.

I have uploaded excel file with ' inputFileUpload' tag of JSF and given value using BEANS as #{myBeans.myFile} to the tag. Now in backbean java file I can't able to get that file so that I can process or parse excel file. I declared it as follows
String inputFile= " #{myBeans.myFile}". But its not working. I don't know whether its right??. I also given getters & setters for 'inputFile' . But when i give direct path of the file like- String inputFile="c:/upload/test.xls" I am able to process that excel file file successfully. I have used POI to parse excel file.

Also I am able to display contents of xls from JSf form in the browser. Although I am getting it on the tomact console. I used following code to parse and display xls file contents.


Can anybody suggest solution to this. Also how to display xls file contents to browser with JSF form.

public String fileSubmit() throws IOException
{

inputFile= "c:/upload/test.xls";


//inputFile="#{attend.inputFile}";

List cellDataList = new ArrayList();



try
{
/*
* Create a new instance for FileInputStream class
*/
FileInputStream fileInputStream = new FileInputStream(inputFile);

/*
* Create a new instance for POIFSFileSystem class
*/

POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);

/*
* Create a new instance for HSSFWorkBook Class
*/

HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
HSSFSheet hssfSheet = workBook.getSheetAt(0);

/*
* Iterate the rows and cells of the spreadsheet to get all the data.
*/

Iterator rowIterator = hssfSheet.rowIterator();

while (rowIterator.hasNext())
{
HSSFRow hssfRow = (HSSFRow) rowIterator.next();
Iterator iterator = hssfRow.cellIterator();
List cellTempList = new ArrayList();

while (iterator.hasNext())
{
HSSFCell hssfCell = (HSSFCell) iterator.next();
cellTempList.add(hssfCell);
}
cellDataList.add(cellTempList);
}
}
catch (Exception e)
{
e.printStackTrace();
}


printToConsole(cellDataList);
// List retList=printToConsole(cellDataList);

return "upLoaded";
}

private List printToConsole(List cellDataList)
{
for (int i = 0; i < cellDataList.size(); i++)
{
List cellTempList = (List) cellDataList.get(i);
for (int j = 0; j < cellTempList.size(); j++)
{
HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);

String stringCellValue = hssfCell.toString();
System.out.print(stringCellValue + "\t");




}
System.out.println();


}


return cellDataList;



}





Thanks...
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!