I am trying to load contents of file in the center layout. On selection event of tree node. But I am not able to display it in the center layout. When i refresh the page then also it is not displaying the contents of file.
This is my xhtml page.I am going wrong somewhere?
<h:body>
<h:form id="form">
<h:commandLink id="back" action="Welcome?faces-redirect=true" type="link"/>
<p:layout fullPage="true">
<p:layoutUnit position="west" size="200" header=
"document List" resizable="true" closable="false" collapsible="false">
<h:outputText value="Searched document's " />
<p:tree value="#{searchContent.root}" var="node" dynamic="true" selectionMode="single"
selection="#{searchContent.singleSelectedNode}">
<p:treeNode >
<h:outputText value="#{node}" />
</p:treeNode>
<p:ajax event="select" listener="#{searchContent.onNodeSelect}"/>
</p:tree>
</p:layoutUnit>
<p:layoutUnit position="east" size="200" header=
"extra" resizable="true" closable="false" collapsible="false">
<h:outputText value="Uploaded by Author's Name" />
</p:layoutUnit>
<p:layoutUnit position="center">
<!-- <h:panelGroup id ="test">-->
<h:outputText value="#{searchContent.fileData}" />
<!-- </h:panelGroup>-->
</p:layoutUnit>
</p:layout>
</h:form>
</h:body>
and here is my managed bean of this page.on select event I am getting the name of the node.And I am reading the file contents line by line. I am getting the contents properly but not able to display in layout
public void onNodeSelect(NodeSelectEvent event) throws FileNotFoundException, IOException {
String path = null;
FileInputStream fis = null;
COSDocument cosdocument = null;
Document doc = new Document();
TreeNode treeNode = event.getTreeNode();
String namecheck = treeNode.toString();
System.out.println("\t" + namecheck);
String name = null, fullname = null, filePath = null;
System.out.println("treeNode contains:" + treeNode);
System.out.println("Node Data ::" + treeNode + " :: Selected");
int _icnt = 0;
while (_icnt < treeList.size()) {
name = treeList.get(_icnt);
System.out.println("Name :" + name);
fullname = field.get(_icnt);
System.out.println("Full Name:" + fullname);
//String nodeTokens[] = name.split(Pattern.quote("."));
if (namecheck.equalsIgnoreCase(name)) {
System.out.println("*******************************");
break;
}
System.out.println(MessageFormat.format("Icnt is:{0}", _icnt++));
}
System.out.println("After while loop");
/*
Database Call to get the filePath based on fileName
from f.getName() .
*/
String result = UserDAO.getFileName(fullname);
System.out.println("Result" + result);
if (!(result.equals(""))) {
File f = new File(result);
if (f.isFile()) {
if (f.getName().endsWith(".docx")) {
try {
fileData = null;
path = f.getAbsolutePath();
fis = new FileInputStream(f.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = document.getParagraphs();
for(XWPFParagraph paras : paragraphs){
fileData = paras.getText();
System.out.println("File data of docx file is:"+fileData);
}
System.out.println("Path is:" + path);
} catch (Exception e) {
System.err.println("Exception in reading docx file is:");
e.printStackTrace();
} finally {
fis.close();
}
} else if (f.getName().endsWith(".doc")) {
try{
fileData = null;
path = f.getAbsolutePath();
System.out.println("Path is:" + path);
fis = new FileInputStream(f.getAbsolutePath());
HWPFDocument hwpfDoc = new HWPFDocument(fis);
WordExtractor wrdExtract = new WordExtractor(hwpfDoc);
String[] paragraphText = wrdExtract.getParagraphText();
for (String paragraph : paragraphText) {
fileData = paragraph;
System.out.println("File Data of doc file is:" + fileData);
}
}
catch(Exception ex){
System.err.println("Exception in reading doc file is:");ex.printStackTrace();
}
finally{
fis.close();
}
} else {
if (f.getName().endsWith(".pdf")) {
try{
fileData = null;
path = f.getAbsolutePath();
System.out.println("Path is:" + path);
PDFParser parser = new PDFParser(new FileInputStream(f.getAbsolutePath()));
parser.parse();
cosdocument = parser.getDocument();
PDFTextStripper stripper = new PDFTextStripper();
fileData = stripper.getText(new PDDocument(cosdocument));
System.out.println("File Data of pdf is:"+fileData);
}catch(Exception ex){
System.err.println("Exxception in reading pdf is:");ex.printStackTrace();
}
finally{
cosdocument.close();
}
} else {
if (f.getName().endsWith(".txt")) {
fileData = null;
path = f.getAbsolutePath();
System.out.println("Path is:" + path);
BufferedReader br = new BufferedReader(new FileReader(f));
String line = null;
while ((line = br.readLine()) != null) {
fileData = line;
System.out.println("fileData:" + fileData);
}
System.out.println("fileData:" + fileData);
}
}
}
}
}
}