• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save inputText value to a file

 
Daniel Vlad
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as the title of my question states, I need to figure out a way to write the contents of a JSF inputText to a file. I want to build a small UI which will offer the user the posibility to write some math formulas in an easier way(hence the UI) and be able to save them to a .txt (or something similar) file. I have been trying for about 8-10 hours now and the best i've got is:



And the Bean:




I'm pretty sure most of what i did there is wrong so any help would be appreciated, even if it is some directions to posts which treat simmilar issues so i can try and get it from there. I don't want to be spoonfed or anything, the problem is i have never worked with JSF(i started reading about it yesterday) so as i said, even some links to some documentation which could help me(i've been googling like crazy since i started) or guide me a bit will be greatly appreciated.

Thanks,
Daniel
 
Marcos Silvestri
Ranch Hand
Posts: 62
Chrome Java Mac
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello from Brazil, Daniel!

Your code is not as much wrong as you think, you demonstrate to have read the JSF documentation and is correctly wiring the view with its respective bean, as shown in the code.

I've recently achieved what you want as follows:

I first created an array of bytes to store the text I wanted:



One note is that "listaLinhasArquivo" in the code above had all the text I wanted, data gathered with the help of the class StringBuilder, something specific to my scenario.

After creating the array of bytes, I created a file called "marcos.txt" on the server and filled it with the data of my array, as follows:



With that code, I successfully created a file on the server with the content I wanted. In your scenario, try to replace the content of the 'try' block for something similar and check to see if it works for you.

Best regards!
 
Daniel Vlad
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it worked . Now I'm working on adding the selected values from a couple of "selectOneMenu's" to the file.
 
Marcos Silvestri
Ranch Hand
Posts: 62
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great man!

In the end, you did not have a JSF specific problem. You're good to go now, up and away

Cheers from Brazil!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic