3 Replies Latest reply on Apr 15, 2011 1:01 PM by Val Blant

    How to access an image as a RichFaces resource?

    Val Blant Newbie

      I was wondering if anyone knows how to access an image resource in RichFaces. I need this b/c I am trying to make a self contained JSF component, so the images cannot be served as usual on my context path.

      So let's say I created an InternetResource like this in my renderer:

      InternetResource temp = getResource("/ca/gc/agr/agrishare/web/jsf/components/ajaxfileupload/images/paperclip.gif");

      System.out.println(temp.getUri(context, component));

       

      This will print: /AgriShare/a4j/g/3_3_3.Finalca/gc/agr/agrishare/web/jsf/components/ajaxfileupload/images/paperclip.gif.jsf

       

      Great. Now I want to access this image resource from a Facelet that is internal to my component.

       

      How do I figure the correct URL? Is there a standard way to do this? By looking at the code, I ended up doing it like this in my Facelet:

       

      <c:set var="resourceContext" value="#{facesContext.externalContext.applicationMap['org.ajax4jsf.webapp.WebXml'].globalResourcePrefix}" />

       

      <h:graphicImage value="#{resourceContext}ca/gc/agr/agrishare/web/jsf/components/ajaxfileupload/images/paperclip.gif.jsf" />

       

      but this seems like a very messy way to do this. Is there a better way?