-3

I've been googling all over the place for information on how to display content from a .txt file onto a web page using JSF with no success.

From what I think/guess, the basic jsf form would be something like

<h:outputText value="#{beanName.printTextFileMethod}"/>

or something.

Help on how to set up bean appreciated. I tried playing with InputStream/BufferedStream, having a lot of problem just trying to get rid of the red lines in codes. Also I'm absolutely horrid at defining relative path. And absolute path doesn't seem to work with inputstream?

Thank you for your time.

kolossus
  • 19,953
  • 3
  • 45
  • 94
user1892752
  • 1
  • 1
  • 4

1 Answers1

0
    public class TextFileBean{   
        String completeMessage = null;
         public TextFileBean(){
          try{
           //read data from the text file
           java.io.BufferedReader in=
              new java.io.BufferedReader(
                new java.io.InputStreamReader(
                  TextFileBean.this.getClass().
                   getResourceAsStream("txtFile.txt"
               )));
 System.out.println("in :" +in);
           readData(in);
           in.close();
           } catch (java.io.IOException IOex) {
             System.out.println("IO Error :" +IOex);
           }
         }    

        private void readData(BufferedReader br) {
        // dosomethig
        String line = null;     
        StringBuffer appendMessage = null;
        try {
            appendMessage = new StringBuffer(16384);
            while ((line = br.readLine()) != null) {
                appendMessage.append(line);
                appendMessage.append('\n');
            }
            if (appendMessage != null) {
                completeMessage = appendMessage.toString();
            }
        } catch (Exception e) {
        }

    }

    public String printTextFileMethod()
    {

        System.out.println("completeMessage:: "+ completeMessage);         
            return completeMessage;
     }

  }
Mohammod Hossain
  • 4,024
  • 2
  • 23
  • 34