0

I am using jsf in netbeans (glassfish) and i'd like to edit my Create form to include a file upload component that will send the image directory to the corresponding image field in mysql once the form is submitted. I have tried to change my code from:

<h:inputText id="imageUrl" value="#{artefactsController.selected.imageUrl}" title="#{bundle.CreateArtefactsTitle_imageUrl}"/>

to:

<t:inputFileUpload id="imageUrl" value="#{artefactsController.selected.imageUrl}" title="#{bundle.CreateArtefactsTitle_imageUrl}"/>

This is using the myfaces component(tomahawk) Is there any way i can pass the value of the upload field to the input textbox ? Or perhaps i need to call some method. I'd appreciate it if anyone could tell me on how to get the directory into the database using the form i already have. The forms were generated by the entities i had already defined.

i need at least a hint on how to link the upload component's managed bean to the:

value="#{artefactsController.selected.imageUrl}" 

perhaps a

valuechangelistener="#{componentbean.getfilename()"

i just need someone to iron out the logic for me please!

  • BalusC (JSF expert) has a good answer to this problem: [How to upload file in JSF](http://stackoverflow.com/a/8465808/1065197). – Luiggi Mendoza Aug 04 '12 at 18:17
  • thanks but i'm having difficulties with that code. I still need to pass the file directory to an already existing managed bean that will then pass the file directory to the database – Blessing Sithole Aug 05 '12 at 12:16
  • You don't need the file directory, just the file name, you will receive the file as a byte array, so you can manipulate that data: createthe file in another directory, save it to your database in a blob field or other things – Luiggi Mendoza Aug 05 '12 at 16:23
  • Sorry to bother you once more Luiggi, you see the problem is later on I will need to carry out an image search based on the file directories. the rest of the code is set and I'd simply like to add an upload function rather than have users type in the directory. – Blessing Sithole Aug 06 '12 at 19:41
  • When the user uploads a file, its full name will be something like "foo/bar/theFile.ext", but once this file is in the server, you could only get "theFile.ext" and the content as a byte array. The user could send his/her file in the end of the universe, but you must handle where those files must be saved in the server (again, not based in the client directory). You're not uploading links to their files or something like that. – Luiggi Mendoza Aug 06 '12 at 20:30
  • hie agian, i have upload and i feel im close but i keep getting a file not found error. (The system cannot find the file specified). I have FileInputStream fin = new FileInputStream(imgfile); is there anything im supposed to add here? – Blessing Sithole Aug 08 '12 at 00:31
  • soughted it out kinda! i have to add the images to the folder first then upload to the database. Hardly convenient but it will do. – Blessing Sithole Aug 08 '12 at 08:34

0 Answers0