0

I would like to make .txt-files accessible for my VaadinApp on a GlassfishServer.

Lets say I have a .txt-file, its content is 12345.

Now, when I click a button on my Vaadin StartPage, I would like to show the Data that has been written into this .txt-file.

I know how Java Input/Output is working but I have no clue how to make those files accessible for my VaadinApplication running on Glassfish 4.1.2.

Is there a folder I can put the .txt-file in, or how would I access the file?

Thanks

Zesa Rex
  • 412
  • 1
  • 4
  • 16

1 Answers1

0

There is component named Label is available in Vaadin. So that, the values which needs to be shown on the screen can be set as a caption/value for that object. This can be done either through constructor or setter in that object.We will set the value through the setter as we need to display the value, once the button is clicked. That can be done like this.

    Label sampleLabel = new Label();
    sampleLabel.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);

Now we will see how this can be added to the label, when a button is clicked.

    Button sampleButton = new Button("Click");
    sampleButton.addClickListener(event -> sampleLabel.setValue(<call the method that reads data from the text file>));

I hope this will be helpful.

Note: Basically you can place the file anywhere in the system. But most preferred way. If you are using maven to build the project, place the files in the resource folder.(src/main/resources)

Sibi
  • 45
  • 1
  • 6
  • Maybe should make more emphasys on your **Note**, it's actually where the OP question is answered. I almost downvoted your answer because it didn't really answer the question. – Shirkam Aug 01 '17 at 11:14
  • Well, yeah. I know how to work with Vaadin Components, I just would like to know if there is a way I can dynamically access Data to lets say, show the data in a Grid. Without rebuilding the App each time I add a new .txt-file – Zesa Rex Aug 01 '17 at 11:34
  • Then it is better to place the file outside the project. Anywhere in the system or Create a folder in your server and put the files in that folder. Access the files with the relative path. – Sibi Aug 01 '17 at 11:46
  • Or, if you know that file will be always there, like a new uploaded file in `/tmp`, you can use it's absolute path. There's no problem reading files inside your filesystem, if you have permissions to read them. If not, it's more a question to https://superuser.com/ – Shirkam Aug 22 '17 at 12:35