5 Replies Latest reply on Nov 24, 2006 3:53 PM by peterj

    Images and portlets

    justin_sane

      I'm new to all this, portlets and jboss thing.
      I wanted to add a simple image on a portlet, but i'm having a lof of difficulties.
      Do I have to use JSP or can I deploy the image directly with the portlet?
      Does anyone have a simple portlet that does that?

        • 1. Re: Images and portlets
          peterj

          Assume you have an image file located at image/some.gif. To access this from a JSP within your portlet, do this:

          <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
          <portlet:defineObjects/>
          <img src="<%= renderRequest.getContextPath() %>/image/some.gif" />


          The context path obtained from the render request provides the proper context.

          Of course, you can create a similar < img > tag from within the portlet itself (I prefer letting the JSP build the user interface).

          • 2. Re: Images and portlets
            justin_sane

            I've tried that, and nothing...
            In the source code of the HTML page there is:

            But I put that image everywhere, and nothing...
            I even created a File, just to see it would read, and it does...
            Strangely with this:
            java.io.File file = new java.io.File(renderRequest.getContextPath()+"/images/dodemo.gif");
            out.println(file.getAbsolutePath());

            I got C:\tester\images\dodemo.gif!

            • 3. Re: Images and portlets
              pl.de

              Do you have a running Portlet? (A war file with the right structure, depolyable and outputting some text?

              If yes try this:

              1. create the image folder and copy images

              your app
              *
              |
              + - - + - - WEB-INF (your web- folder, you should have already)
              | + - index.html
              |
              + - - + - - images (NEW)
               + myImage.jpg (NEW)
              
              



              2. link your image



              • 4. Re: Images and portlets
                justin_sane

                Finally got it running.
                The problem was that my ecllipse project got the directory of the images in the wrong place, so it didn't exported it to the war file.
                I tried to put the files by hand but, nothing, because it shoul be inside the war.
                So many time lost with this, how stupid of me?!
                Than you for your help!

                • 5. Re: Images and portlets
                  peterj

                  Now you know why I don't trust Eclipse (or any IDE) to do my builds or packaging. I always use Maven 2, or Ant, and I have yet to be surprised. But I am constantly helping people with strange problems where code works for me but not for them only to find out later that they were running/building/packaging within Eclipse or NetBeans.

                  Be that as it may, I am glad you got it running!