Announcement Announcement Module
Collapse
No announcement yet.
How to create a file upload browser in spring roo? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Ok, I found where is the error. I'll try to solve it.

    LuKe

    Comment


    • #17
      Originally posted by lukeb View Post
      Hi Harald,

      I followed your instructions but I got this error:

      2010-11-15 09:26:10,973 [http-8080-5] ERROR org.springframework.web.servlet.tags.MessageTag - No message found under code 'label_my_domain_image' for locale 'en_US'.
      javax.servlet.jsp.JspTagException: No message found under code 'label_my_domain_image' for locale 'en_US'.

      Where is the error?

      LuKe
      The error message is pretty clear. So either add the message or change id="c_my_domain_image_image" to one of your domain objects which already has an entry in application.properties.

      Have a look at the tag libraries to see why this is happening and how ROO is working. Based on the id attribute the label message key is being determined.

      Comment


      • #18
        Finally I was able to upload my file.
        The problem is that the other fields are not stored on the database table.

        Any idea why?

        Furthermore, normally after saving a record roo redirects to a page that show the record just stored.
        In case of the upload form roo return to the form (but the file has been uploaded).

        LuKe

        Comment


        • #19
          Originally posted by lukeb View Post
          Finally I was able to upload my file.
          The problem is that the other fields are not stored on the database table.

          Any idea why?
          LuKe
          Could you show us your entity class and controller?

          Comment


          • #20
            Big:

            Code:
            @RooJavaBean
            @RooToString
            @RooEntity
            public class Big {
            @NotNull @Size(max = 10240) private String content;
            @NotNull @Size(max = 20) private String name;
            @Transient private CommonsMultipartFile file; // added private String fileName; // added private long size; //added public CommonsMultipartFile getFile() {
            [INDENT=2]return file;[/INDENT]
            } // save file to disk ,save filename , file size to database public void setFile(CommonsMultipartFile file) {
            [INDENT=2]this.file = file; this.fileName = file.getOriginalFilename(); this.size = file.getSize(); System.out.println("hehe this.fileName: " + this.fileName + " , " + file.getClass().getName()); try { [/INDENT][INDENT=3]System.out.println("try 01"); InputStream in = file.getInputStream(); FileOutputStream f = new FileOutputStream("/opt/" + file.getOriginalFilename()); int ch = 0; while ((ch = in.read()) != -1) { [/INDENT][INDENT=4]f.write(ch);[/INDENT][INDENT=3]} f.flush(); f.close(); [/INDENT][INDENT=2]} catch (FileNotFoundException e) { [/INDENT][INDENT=3]e.printStackTrace(); [/INDENT][INDENT=2]} catch (IOException e) { [/INDENT][INDENT=3]e.printStackTrace(); [/INDENT][INDENT=2]}[/INDENT]
            }
            }

            BigController:

            Code:
            @RooWebScaffold(path = "bigs", formBackingObject = Big.class)
            @RequestMapping("/bigs")
            @Controller
            public class BigController {
            }
            Last edited by Andrew Swan; Oct 11th, 2011, 06:25 PM. Reason: Added code tags around code snippets

            Comment


            • #21
              Originally posted by lukeb View Post
              Furthermore, normally after saving a record roo redirects to a page that show the record just stored.
              In case of the upload form roo return to the form (but the file has been uploaded).
              LuKe
              You might be running into an exception which is not being displayed. That would explain why you go back to the form and don't see the correct results in the database. You could set a breakpoint in the BigController_Roo_Controller.aj create method to see what's happening.

              BTW, if you only want to move the uploaded file to a different location you can use the transferTo method of CommonsMultipartFile.

              Comment


              • #22
                I've tried to debug on the BigController_Roo_Controller.aj create method but everything seams to run well.

                Here are the debug info:


                Code:
                2010-11-16 11:03:23,194 [http-8080-6] DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter - Using EntityManagerFactory 'entityManagerFactory' for OpenEntityManagerInViewFilter
                2010-11-16 11:03:23,211 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
                2010-11-16 11:03:23,211 [http-8080-6] DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter - Opening JPA EntityManager in OpenEntityManagerInViewFilter
                2010-11-16 11:03:23,211 [http-8080-6] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 12899018032
                2010-11-16 11:03:23,223 [http-8080-6] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'testUpload02' processing POST request for [/testUpload02/bigs]
                2010-11-16 11:03:23,279 [http-8080-6] DEBUG org.springframework.web.multipart.commons.CommonsMultipartResolver - Found multipart file [file] of size 56699 bytes with original filename [locandinaISmall.jpg], stored at [/home/luke/Documents/workspace-sts-2.5.1.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/work/Catalina/localhost/testUpload02/upload__58fe5fca_12c5422792a__8000_00000010.tmp]
                2010-11-16 11:03:23,302 [http-8080-6] DEBUG org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapping [/bigs] to HandlerExecutionChain with handler [com.eidosoft.testupload02.web.BigController@34a083f2] and 4 interceptors
                2010-11-16 11:03:23,320 [http-8080-6] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'com.eidosoft.testupload02.domain.Big': PersistenceElement for transient javax.persistence.EntityManager com.eidosoft.testupload02.domain.Big.entityManager
                2010-11-16 11:03:23,320 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
                2010-11-16 11:03:23,323 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'c' of java.lang.String to @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String
                2010-11-16 11:03:23,323 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'c'
                2010-11-16 11:03:23,347 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value '' of java.lang.String to java.lang.String
                2010-11-16 11:03:23,347 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to ''
                2010-11-16 11:03:23,348 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'n' of java.lang.String to @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String
                2010-11-16 11:03:23,348 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'n'
                2010-11-16 11:03:23,348 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value '' of java.lang.String to long
                2010-11-16 11:03:23,348 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to [null]
                2010-11-16 11:03:23,349 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value [email protected]74f160 of org.springframework.web.multipart.commons.CommonsMultipartFile to @javax.persistence.Transient org.springframework.web.multipart.commons.CommonsMultipartFile
                2010-11-16 11:03:23,350 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to [email protected]74f160
                fileName: locandinaISmall.jpg
                size: 56699
                 hehe  this.fileName: locandinaISmall.jpg ,  org.springframework.web.multipart.commons.CommonsMultipartFile
                try 01
                try end
                2010-11-16 11:03:23,492 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.constraints.impl.NotNullValidator'
                2010-11-16 11:03:23,492 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.constraints.impl.NotNullValidator'
                2010-11-16 11:03:23,492 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.constraints.impl.SizeValidatorForString'
                2010-11-16 11:03:23,492 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.constraints.impl.SizeValidatorForString'
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.constraints.impl.NotNullValidator'
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.constraints.impl.NotNullValidator'
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.constraints.impl.SizeValidatorForString'
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.constraints.impl.SizeValidatorForString'
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.web.bind.annotation.support.HandlerMethodInvoker - Invoking request handler method: public java.lang.String com.eidosoft.testupload02.web.BigController.create(com.eidosoft.testupload02.domain.Big,org.springframework.validation.BindingResult,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)
                2010-11-16 11:03:23,493 [http-8080-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'bigs/create'; URL [bigs/create]] in DispatcherServlet with name 'testUpload02'
                2010-11-16 11:03:23,494 [http-8080-6] DEBUG org.springframework.web.servlet.view.tiles2.TilesView - Added model object 'big' of type [com.eidosoft.testupload02.domain.Big] to request in view with name 'bigs/create'
                2010-11-16 11:03:23,494 [http-8080-6] DEBUG org.springframework.web.servlet.view.tiles2.TilesView - Added model object 'org.springframework.validation.BindingResult.big' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'bigs/create'
                2010-11-16 11:03:23,494 [http-8080-6] DEBUG org.apache.tiles.impl.BasicTilesContainer - Render request recieved for definition 'bigs/create'
                2010-11-16 11:03:23,615 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'c' of @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String to java.lang.String
                2010-11-16 11:03:23,615 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'c'
                2010-11-16 11:03:23,616 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'c' of @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String to java.lang.String
                2010-11-16 11:03:23,616 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'c'
                2010-11-16 11:03:23,631 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'n' of @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String to java.lang.String
                2010-11-16 11:03:23,631 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'n'
                2010-11-16 11:03:23,632 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converting value 'n' of @javax.validation.constraints.NotNull @javax.validation.constraints.Size java.lang.String to java.lang.String
                2010-11-16 11:03:23,632 [http-8080-6] DEBUG org.springframework.core.convert.support.GenericConversionService - Converted to 'n'
                2010-11-16 11:03:23,659 [http-8080-6] DEBUG org.springframework.web.multipart.commons.CommonsMultipartResolver - Cleaning up multipart file [file] with original filename [locandinaISmall.jpg], stored at [/home/luke/Documents/workspace-sts-2.5.1.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/work/Catalina/localhost/testUpload02/upload__58fe5fca_12c5422792a__8000_00000010.tmp]
                2010-11-16 11:03:23,660 [http-8080-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
                2010-11-16 11:03:23,660 [http-8080-6] DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter - Closing JPA EntityManager in OpenEntityManagerInViewFilter
                2010-11-16 11:03:23,660 [http-8080-6] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager

                Comment


                • #23
                  And when updating?

                  Does anyone has been able to apply this to the <form:update>?

                  As soon as I add the enctype="multipart/form-data" to the form:update, as I did successfully to form:create, I get a persistence error:

                  org.hibernate.PersistentObjectException: detached entity passed to persist: valizatools.com.server.domain.Artist; nested exception is javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: valizatools.com.server.domain.Artist

                  Comment


                  • #24
                    G uys,
                    Dont miss 2nd part on fileupload article series...this complementary to the one referred injira 442. It will address very large blob.

                    B. Roogards
                    jD

                    Comment


                    • #25
                      I can't wait!

                      Comment


                      • #26
                        How to upload excel data to database in STS?

                        I really don't know how to do it.

                        Comment


                        • #27
                          Maybe you should give a look to this video:
                          http://www.youtube.com/watch?v=0cZCgrskkaQ

                          I don't know if it could help you, but it could be a start.
                          Bye

                          Comment


                          • #28
                            @adam37

                            Oh no, you got the buggy one...
                            I wished you would have used the latest version of my tutorial for your video. The one without the nasty exception.

                            Too bad
                            jD

                            Comment


                            • #29
                              :S...
                              Could you be more precise?
                              Where can I find the second version of your tutorial?
                              Thank you very much for the tutorial!!!

                              Comment


                              • #30
                                (:S...)++

                                Tell you what... Put an attribution notice -given credit to the tutorial's author; which I truly believe is the correct way to proceed anyway- to the video and I let you access to 2nd version.

                                As a matter of fact, I have a business proposition for you since -with exception of the music- I think you did a great job creating a video of my tutorial.

                                We can join efforts for serving better the SR community; I have many-many of those tutorials -that you can turn into videos- which the SR community has shown great interest on them.

                                What you think?

                                B. Roogards
                                jD @ http://pragmatikroo.blogspot.com
                                Last edited by delgad9; Apr 22nd, 2012, 02:07 PM.

                                Comment

                                Working...
                                X