HTML code - JAVASCRIPT It read a txt file from the computer and puts its value into an html input
<input type="file" id="files" name="files[]" multiple />
<input type="text" required name="txtstart" style="width:150px" value="">
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var saida = "";
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
saida+=e.target.result;
document.querySelector("[name='txtstart']").value = saida;
};
})(f);
// Read in the image file as a data URL.
reader.readAsBinaryString(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
I want to put this same logic in primeface, but I can not seem to get the selected file into a p: inputTextarea tried to do the same in the HTML without the p: but even so javascript does not run.
In short, I need to read a file from the computer and put its value inside the component below:
<p:inputTextarea value="#{polylinesView.texto}" rows="7" cols="20"
scrollHeight="10" />