Results 1 to 20 of 21
Thread: File Upload
- 11-01-2012, 01:22 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
File Upload
Hi, guys!
RichFaces - Open Source Rich JSF Components - Combo Box Component
I've used this link to help me about my problem, but I can't do my JSP calls the method "Listener". I put a breakpoint and nothing...
I want to upload just one image and I have two ways to save the image...
I catch the image's path to save it in the DB...
Or I copy the imagem and put it inside default folder in my project and save its name in the BD.
Please, help me!
- 11-01-2012, 02:27 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
What does your code look like at the moment?
Apache has a FileUpload package which might prove useful.Please do not ask for code as refusal often offends.
- 11-01-2012, 03:53 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
I tryed to use that example... But I changed all the code... My boss wants this part of the project fastly. Basically, I need to put a component to select images. The code about copy an image a catch its path I have.
The component of the link that I send I think it's too complex... I need just the paths, not uploads, datas, etc.
<td><hx:fileupload styleClass="fileupload" id="fileupload1"
value="#{pc_Recomendacoes.filePath">
<hx:fileProp name="fileName" value="#{pc_Recomendacoes.fileName"></hx:fileProp>
</hx:fileupload></td>
Now, I'm trying to use this component, but it does not work...
- 11-01-2012, 04:27 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
"it does not work" is not the most useful statement.
What does the code on your server look like?
Please use [code] tags [/code] when posting code.Please do not ask for code as refusal often offends.
- 11-01-2012, 04:41 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
The page does not open.
Exceção Original:
Mensagem de Erro: java.lang.IllegalStateException
Código de Erro: 500
Servlet de Destino: null
Pilha de Erro:
java.lang.IllegalStateException
Mensagem de Erro: java.lang.NullPointerException: FacesContext is null
Código de Erro: 0
Servlet de Destino: null
Pilha de Erro:
java.lang.NullPointerException: FacesContext is null
The error is in Portuguese, but I think you will understand.
The code...
Java Code:<td><hx:fileupload styleClass="fileupload" id="fileupload1" value="#{pc_Recomendacoes.filePath"> <hx:fileProp name="fileName" value="#{pc_Recomendacoes.fileName"></hx:fileProp> </hx:fileupload></td
- 11-01-2012, 04:51 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
I've just noticed that this is a JSF question, not JSP.
I'll move it into the correct forum.
I've not used JSF.
But you also haven't shown the server code, just the code for the page.Please do not ask for code as refusal often offends.
- 11-01-2012, 05:25 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
No... It's a JSP. Servlet/JSP. I could print a image of my page for you, but the company blocks uploads...
I did it. The page works now... the tag "f:view" did not let my page to load.
Now, I will do the rest. Catch the path, copy the file, insert a new register.
- 11-05-2012, 01:31 PM #8
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
That's my code. My problem is about my variables... "fileContent", "fileName" and "fileType" are always null... I have a java class with setters and gettters of these variables.Java Code:<td><hx:scriptCollector id="scriptCollector"> <hx:fileupload styleClass="fileupload" id="uploadImage" size="48" value="#{pc_Recomendacoes.fileContent}" accept="image/jpg, image/gif, image/png, image/bmp" exclude="txt, html, exe, doc"> <hx:fileProp name="fileName" value="#{pc_Recomendacoes.fileName}" /> <hx:fileProp name="contentType" value="#{pc_Recomendacoes.fileType}" /> </hx:fileupload> </hx:scriptCollector></td>
I have to select an image and get its path to save in my BD. If anybody has any idea about my problem or a new way to do that, I would get happy.
Thanks!
- 11-05-2012, 02:39 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
You say this is a JSP/Servlet thing, yet you are using a JSF component there.
It's going to be difficult to help if you don't clarify what technology you are trying to use.Please do not ask for code as refusal often offends.
- 11-05-2012, 05:20 PM #10
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
I'm so sorry. I'm a new employee... I just used Java, not Java Web, so I've gotten cofused when the subject is JSP's, JSF's and Servlet's... But I have to learn fast. I have to deliver the project on December.
Well... I will try to explain...
The file with that code is a ".jsp" extension... So... I thought It was a JSP, but is it a JSF? Explain me, please.
At this file, I have many kind of tags...
So... Do you undestand? I hope so...Java Code:<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> <%@taglib uri="http://richfaces.org/rich" prefix="rich"%> <%@taglib uri="http://richfaces.org/a4j" prefix="ajax"%>
Thanks!
- 11-05-2012, 05:34 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
Looks like JSF to me which, as I said, I don't know well enough to help.
All I can say is that a null FacesContext sounds like a setup problem, but I could well be very wrong on that account.Please do not ask for code as refusal often offends.
- 11-05-2012, 05:47 PM #12
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
What part of the code do yu need?
Well... I have this ".jsp" with my components... Buttons, tables, fields, etc. All of them work very well.
Now, My File Upload component does not get an error too. The page opens... at least...
This page has a class to represent it. Like this... "Recomendacoes_tela.jsp" and "Recomendacoes_tela.java".
I thought I could do the same with File Upload component, But it does not seem...
Thanks!
The "Pc_Recomendacoes" that is in my ".jsp" is my Managed Bean.
We work this way here... A page (.jsp) has a class (..._tela) and a bean (pc_...).
If I want to use a outputtext, for example, I put the tag value "Pc_Recomendacoes.name" and at java's class, I put a set and a get method for attribute "Name".
I thought
- 11-05-2012, 06:20 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
It's Java Server Faces.
I do not know that well enough to help you.
If it was straight JSP then I could.Please do not ask for code as refusal often offends.
- 11-05-2012, 07:42 PM #14
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
- 11-06-2012, 11:31 AM #15
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
Hi guys!
I find a code, but a part of it does not work. See...
I import the library of "ContentElement", but the method "getFileUploadInput" get an error. Does anybody know any solution?Java Code:public String doSubmitJSFFormButtonAction() { try { ContentElement content = (ContentElement) getFileUploadInput().getValue(); byte[] fileBytes = content.getContentValue(); // file byte array String filename = getFileUploadInput().getFilename(); // file name /* Extracting the file name in case the complete path was received */ filename = new File(filename).getName(); /* Writing file bytes to an output stream */ filename = "C:\\UploadTrials\\JSF-" + filename; FileOutputStream fileOut = new FileOutputStream(filename); fileOut.write(fileBytes, 0, fileBytes.length); fileOut.flush(); fileOut.close(); System.out.println("DEBUG - File saved at >> " + filename); } catch (Exception e) { e.printStackTrace(); } return "SamePage"; }
Thanks for all!
- 11-06-2012, 12:24 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
What error?
Please do not ask for code as refusal often offends.
- 11-06-2012, 12:45 PM #17
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
The method getFileUploadInput() is undefined for the type Recomendacoes_tela
But there is no implementation of this method...
Implementing a file upload portlet in IBM WebSphere Portal
- 11-06-2012, 12:59 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: File Upload
Do you have IBM Rational® Application Developer?
Because I am assuming the selection of that FileUpload widget produces some base code that you then expand on.Please do not ask for code as refusal often offends.
- 11-06-2012, 01:09 PM #19
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
Yes. The company uses it.
I can import the library "com.ibm.faces.FileUpload.ContentElement", but the method does not exist...
It looks like this method will get the information about my upload... This is the most important part of the code. hehe
- 11-12-2012, 06:02 PM #20
Member
- Join Date
- Oct 2012
- Posts
- 18
- Rep Power
- 0
Re: File Upload
Hi guys, I find this link 6.11.5.* < rich:fileUpload > available since 3.2.0
Now, I can catch the path of a selected image. It's working perfectly, but I need to set the path in a variable.
This code...
It shows a message alert with path fo the image. If I could set this value in a variable, my problem is solved. I don't know how to do this. Any help?Java Code:onupload="alert(event.memo.entry.fileName);"
Thanks!!!
Similar Threads
-
File upload
By bekir in forum Java ServletReplies: 2Last Post: 04-08-2011, 03:17 PM -
:large file upload to server(chunk upload)
By tommy_725 in forum NetworkingReplies: 0Last Post: 10-16-2009, 12:21 AM -
how to upload a file?
By tommy in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 06-30-2008, 02:50 PM -
file upload
By sundarjothi in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-27-2008, 11:52 AM -
File Upload
By ShoeNinja in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-09-2007, 10:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks