Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: File Upload

  1. #1
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default 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!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  3. #3
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Quote Originally Posted by takugian View Post
    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!
    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...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  5. #5
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Quote Originally Posted by Tolls View Post
    "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.
    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

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  7. #7
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default 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.

  8. #8
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    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>
    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.

    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!

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  10. #10
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Quote Originally Posted by Tolls View Post
    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.
    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...

    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"%>
    So... Do you undestand? I hope so...

    Thanks!

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  12. #12
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default 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

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  14. #14
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Quote Originally Posted by Tolls View Post
    It's Java Server Faces.
    I do not know that well enough to help you.

    If it was straight JSP then I could.
    Okay... Thanks so much!!!

    I need to do this component works. The part about java is okay...

    When I find something about my problem, it's the part of java heheh I never find about JSF.

  15. #15
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Hi guys!

    I find a code, but a part of it does not work. See...

    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";
    	}
    I import the library of "ContentElement", but the method "getFileUploadInput" get an error. Does anybody know any solution?

    Thanks for all!

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: File Upload

    What error?
    Please do not ask for code as refusal often offends.

  17. #17
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: File Upload

    Quote Originally Posted by Tolls View Post
    What error?
    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

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  19. #19
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default 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

  20. #20
    takugian is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default 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...

    Java Code:
    onupload="alert(event.memo.entry.fileName);"
    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?

    Thanks!!!

Page 1 of 2 12 LastLast

Similar Threads

  1. File upload
    By bekir in forum Java Servlet
    Replies: 2
    Last Post: 04-08-2011, 03:17 PM
  2. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM
  3. how to upload a file?
    By tommy in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-30-2008, 02:50 PM
  4. file upload
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-27-2008, 11:52 AM
  5. File Upload
    By ShoeNinja in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-09-2007, 10:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •