1 2 Previous Next 15 Replies Latest reply on Nov 1, 2007 2:31 PM by Flavio Ferreira

    Tutorial: Handling images in your Seam application

    enrokuta Newbie

      I have just completed a five part tutorial that shows you one possible way of handling images in Seam. The tutorial consists of five parts:

      Part One: Defining the database model and entities envolved:
      http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-i-db.html

      Part Two: Uploading images using s:fileUpload and persisting them in the database:
      http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-ii.html

      Part Three: Using a seam component to scale uploaded images and to generate thumbnails:
      http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-iii.html

      Part Four: Using a servlet with the help of seam context filter to view and cache images on the client:
      http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-iv.html

      Part Five: Restricting access to pages based on Seam simplfied security mode:
      http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-v.html

      Feedback, comments and suggestions are much appreciated.

        • 1. Re: Tutorial: Handling images in your Seam application
          Pete Muir Master

          Please link to these off the Seam wiki.

          • 4. Re: Tutorial: Handling images in your Seam application
            Damian Harvey Master

            Some great tips in there. Already put some to good use.

            Thanks!

            Damian.

            • 5. Re: Tutorial: Handling images in your Seam application
              Damian Harvey Master

              I had an error "Wrong column type....expected blob" when I used the mysql mediumblob datatype. This post http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046291#4046291 has a solution that works for me. Eg:

               @Lob
               @Basic(fetch=FetchType.LAZY)
               @Column(name = "data", nullable = false, columnDefinition="mediumblob")
               private byte[] data;
              

              Cheers,

              Damian.

              • 9. Re: Tutorial: Handling images in your Seam application
                Flavio Ferreira Newbie

                can someone post the source of ArtworkServlet.java to see what am i doing wrong?

                • 11. Re: Tutorial: Handling images in your Seam application
                  Flavio Ferreira Newbie

                  when i call something like em.query(...) returns an exception:

                  16:00:30,890 ERROR [STDERR] java.lang.NullPointerException
                  16:00:30,890 ERROR [STDERR] at com.flavio.b.ArtworkServlet.doGet(ArtworkServlet.java:59)
                  16:00:30,890 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
                  16:00:30,890 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                  16:00:30,890 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                  16:00:30,890 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  16:00:31,046 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                  16:00:31,046 ERROR [STDERR] at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                  16:00:31,046 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,046 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                  16:00:31,046 ERROR [STDERR] at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,125 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
                  16:00:31,125 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                  16:00:31,125 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                  16:00:31,625 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                  16:00:31,625 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                  16:00:31,625 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  16:00:31,625 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                  16:00:31,625 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                  16:00:32,125 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                  16:00:32,125 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                  16:00:32,125 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                  16:00:32,125 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                  16:00:32,125 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                  16:00:32,125 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                  16:00:32,125 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                  16:00:32,125 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
                  


                  i tried comment the line:
                  EntityManager em = (EntityManager) Component.getInstance("entityManager");

                  and inject entityManager by hand with @In:
                  @In(create = true, value = "entityManager")
                  private EntityManager em;


                  • 12. Re: Tutorial: Handling images in your Seam application
                    enrokuta Newbie

                    Did you define the web:context-filter in components.xml? Can you post some code around line 59?

                    • 13. Re: Tutorial: Handling images in your Seam application
                      Flavio Ferreira Newbie

                       

                      <components xmlns="http://jboss.com/products/seam/components"
                       xmlns:core="http://jboss.com/products/seam/core"
                       xmlns:persistence="http://jboss.com/products/seam/persistence"
                       xmlns:web="http://jboss.com/products/seam/web"
                       xmlns:drools="http://jboss.com/products/seam/drools"
                       xmlns:bpm="http://jboss.com/products/seam/bpm"
                       xmlns:security="http://jboss.com/products/seam/security"
                       xmlns:mail="http://jboss.com/products/seam/mail"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation=
                       "http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                       http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd"
                       >
                      ...
                      <web:context-filter url-pattern="/b/*" />
                      ...
                      </components>
                      


                      ArtworkServlet.java
                      
                       String query = "from gs_artwork_info a where a.fileName = :filename";
                       System.out.println(this.em.toString());
                       artworkInfo = (ArtworkInfo) this.em.createQuery(query).setParameter("filename",fileName).getSingleResult();
                      


                      • 14. Re: Tutorial: Handling images in your Seam application
                        enrokuta Newbie

                        You should be defining the EntityManager as a local variable of the doGet method rather than having it as a member.
                        Seam injection cannot be applied to servlets. You have to use Component.getInstance instead.

                        1 2 Previous Next