14 Replies Latest reply on Aug 14, 2008 11:40 AM by andrei_exadel

    rich:fileUpload as part of form is not working

    khaled_288

      Hi all,

      I want to use rich:fileUpload component as part a form, to be submitted one time .. for example in my case:
      I have a form to create a new client account .. so the user will fill the client id, name, and logo image THEN the user submit the form one time.
      In create method (the action) i will take all the inputs and insert them directly to DB.

      The problem:
      rich:fileUpload component is using AJAX in uploading, so the listener only can see the uploaded file, but when the user submit the form, the file is gone.

      I'm using rich:fileUpload as a part of h:form as follow


      <f:view><h:form>
      
      <h:inputText value="#{createNewClient.client.id}" id="idInput" />
      
      <h:inputText value="#{createNewClient.client.name}" id="nameInput" />
      
      <rich:fileUpload uploadData="#{createNewClient.uploadData}" id="logoImageInput" ajaxSingle="true"
       rendered="#{not createNewClient.created}" maxFilesQuantity="1"
       acceptedTypes="jpg, gif, png, bmp" immediate="true" listHeight="70px"
       fileUploadListener="#{createNewClient.uploadListener}" immediateUpload="true">
      
      </rich:fileUpload>
      
      <h:commandButton value="#{msg.create}" action="#{createNewClient.create}" />
      
      </h:form>
      </f:view>



      please help me,

      can I use rich:fileUpload as a part of form?? HOW??

      thanks

        • 1. Re: rich:fileUpload as part of form is not working
          khaled_288


          if rich:fileUpload is not designed for this usage; what is the alternative solution for my need:
          upload single image as a part of the form.

          while the core JSF does not have such component. (there is no <h:inpuFile>


          i need your help :)

          • 2. Re: rich:fileUpload as part of form is not working
            ilya_shaikovsky

            We working under this right now. As alternative you could use t:inputFile.

            • 3. Re: rich:fileUpload as part of form is not working
              khaled_288


              thank you for fast response :)

              • 4. Re: rich:fileUpload as part of form is not working
                kdcosta

                hi

                I dono whether this is wht u needed.

                wht i did was , i created a java class with two variable ie string fileName and one to store data.Also its setters and getters.

                when the browse button is clicked, it enters the listener method , there set the filename and the data to the new java class we have created.
                javaclassName.setFilename(); etc etc.

                And then when the commandButton is clicked, get the fileName and the data from that java class.
                ie javaclassName.getFileName(); etc.


                try it.It worked for me.

                • 5. Re: rich:fileUpload as part of form is not working
                  khaled_288

                  kdcosta .. i did not get your idea
                  please could you help me with an example (code snippet)?

                  thanks :)

                  • 6. Re: rich:fileUpload as part of form is not working
                    kdcosta

                    hi

                    im sorry for that.

                    <rich:fileUpload uploadData="#{createNewClient.uploadData}" id="logoImageInput" ajaxSingle="true"
                     rendered="#{not createNewClient.created}" maxFilesQuantity="1"
                     acceptedTypes="jpg, gif, png, bmp" immediate="true" listHeight="70px"
                     fileUploadListener="#{createNewClient.uploadListener}" immediateUpload="true">
                    
                    </rich:fileUpload>


                    Upon uploading , fileUploadListener will called. rt??
                    there u will get the file name of the upload file.
                    For example my listener is like this
                    public void listener(org.richfaces.event.UploadEvent event) {
                     try {
                    
                     event.getUploadItem().getData();
                     item = event.getUploadItem();
                    
                     utility.setLogFilePath(item.getFileName());
                     fileData = event.getUploadItem().getFile();
                     utility.setFileData(this.fileData);
                     } catch (Exception e) {
                     System.out.println(this.getClass().getSimpleName()+"1006"+e.toString());
                     e.printStackTrace();
                     }
                    
                     }



                    I have created a Utility.java class and i have injected that class into my controller class.

                    @Name("utility")
                    @Scope(ScopeType.SESSION)
                    public class Utility {
                    
                     String logFilePath;
                     File fileData;
                    }
                    

                    Also its getter and setters.
                    And when the action of ur commandButton is called

                    <h:commandButton value="#{msg.create}" action="#{createNewClient.create}" />


                    i mean in create method, u can get the filename and the filedata using
                    utility.getLogFilePath(),utility.getFileData()

                    and using the uploading code u can write the filedata.


                    i dono whether this is wht u needed.
                    or else just ignore it .

                    good luck

                    • 7. Re: rich:fileUpload as part of form is not working
                      khaled_288

                      ahaaa now i got you .. so you are saving the uploaded file in the session scope.

                      I think about this but do you think it is right practice to save files in session ?:)

                      1- I think this probably cause memory problems specially under stress load.
                      2- what if the user access the same page from another browser and upload another file .. the old file will be overridden.


                      I think session is the not good place to store files :)

                      • 8. Re: rich:fileUpload as part of form is not working
                        liulei1984

                         

                        "ilya_shaikovsky" wrote:
                        We working under this right now. As alternative you could use t:inputFile.


                        In which version of RF will solve this problem?

                        appreciate!!!

                        I am really eager to know that.

                        Thanks for any reply.

                        • 9. Re: rich:fileUpload as part of form is not working
                          liulei1984

                          I have traced the jira for this,but no hint

                          • 10. Re: rich:fileUpload as part of form is not working

                            Liulei1984,

                            Can you specify in details the functionality you're eager?

                            You'd like to have only upload posibility with form?
                            Or you want to have upload progress information such in case by UPLOAD button?

                            Do you want to have STOP functionality in this case?

                            & etc.

                            Thanks.

                            • 11. Re: rich:fileUpload as part of form is not working
                              liulei1984

                               

                              "andrei_exadel" wrote:
                              Liulei1984,

                              Can you specify in details the functionality you're eager?

                              You'd like to have only upload posibility with form?
                              Or you want to have upload progress information such in case by UPLOAD button?

                              Do you want to have STOP functionality in this case?

                              & etc.

                              Thanks.


                              In my application(Useing Seam Framework), I just want to upload multi files at a time in one form. Not ajax style,but submit the files with the form.

                              what i want is just like below:

                              <h:form id="publish" enctype="multipart/form-data">
                              <rich:fileUpload uploadData="#{eventHome.files}"
                              maxFilesQuantity="5"
                              autoclear="false"
                              addControlLabel="添加图片"
                              uploadControlLabel="上传"
                              clearAllControlLabel="清除所有"
                              clearControlLabel="清除"
                              cancelEntryControlLabel="�消"
                              stopControlLabel="å�œæ¢"
                              stopEntryControlLabel="å�œæ¢" noDuplicate="true"
                              listHeight="150"
                              listWidth="425"
                              style="height:150;"
                              id="upload"
                              acceptedTypes="jpg, gif, png, bmp">
                              </rich:fileUpload>

                              <h:commandLink action="#{eventHome.persist()}">

                              </h:commandLink>
                              </h:form>

                              Once i hit the submit button, all the files data can be received in #{eventHome.files}.

                              Note: "eventHome" is stateless session bean.

                              Thanks for reply!


                              • 12. Re: rich:fileUpload as part of form is not working

                                We'll discuss this soon.

                                • 13. Re: rich:fileUpload as part of form is not working
                                  liulei1984

                                   

                                  "andrei_exadel" wrote:
                                  We'll discuss this soon.


                                  Appreciate!

                                  I'm waiting for the solution.

                                  If you can solve this prolem and release in Version 3.2.2, it will do me a great favor.

                                  Thanks.

                                  Any schedule or jira item comes out, let me know.

                                  I will pay attention to it.


                                  • 14. Re: rich:fileUpload as part of form is not working

                                    The JIRA issue filled: https://jira.jboss.org/jira/browse/RF-4209.

                                    It will be included in 3.2.2 release.