1 Reply Latest reply on Jul 8, 2008 11:35 PM by Dan Allen

    s:graphicImage set your own url possible?

    Susanne Jarl Newbie

      The question is if I can decide the generated url for my images (not just the end of the URL) when I use s:graphicImage. Details explained below:


      I use s:graphicImage to display images that are stored in my database.


      In my web.xml:



      <servlet>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
         </servlet>
          
         <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
         </servlet-mapping>




      In my xhtml:



      <s:graphicImage value="#{recipe.imageMain.image}" fileName="recept/#{recipe.recipeId}/main/#{recipe.imageName}" />




      If I look in the generated html source code the html for the image is


      <img src="http://www.recepten.se/seam/resource/graphicImage/recept/324/main/sill.jpg" />



      My question is how do I decide the generated url totally myself? Right now I can change the ending of it but not the start. I do not want it to start with /seam/resource/graphicImage.


      I want the url to be http://www.recepten.se/images/recept/324/main/sill.jpg
      The reason for this is SEO.


      So the question is: Is it possible to decide the URL for images using graphicImage? Can I use urlrewrite to change the generated URL?

        • 1. Re: s:graphicImage set your own url possible?
          Dan Allen Master

          Unfortuantely, the resource URL is hardcoded, so you would have to override the renderer and inject your custom class in faces-config.xml. I'm afraid that urlrewrite will not help you here because the renderer is implemented as follows:


                public static final String GRAPHIC_IMAGE_RESOURCE_PATH = 
                    "/seam/resource/graphicImage";
          
                writer.startElement(HTML.IMG_ELEM, graphicImage);
                String url = context.getExternalContext().getRequestContextPath()
                         + GraphicImageResource.GRAPHIC_IMAGE_RESOURCE_PATH 
                         + "/" + key + extension;
                writer.writeAttribute(HTML.SRC_ATTR, url, HTML.SRC_ATTR);
                ...
                writer.endElement(HTML.IMG_ELEM);



          I encourage you to override it. Follow a JSF component tutorial to do so (if you aren't familiar with the process). Then you can choose the resource path as you need it and map it as such in web.xml.