3 Replies Latest reply on Aug 15, 2010 5:41 PM by fernando flores

    Share resources beetwen portlets, how?

    fernando flores Newbie



      if my portlet use a image, only put this file into my .war file, right!  But, if I have a particular resource (per example a images big set), and these must be in all portlets, then isn't eficient that I put these files into eeach portlet, then:


      1. where copy the folder with my images for all portlets can use it?


      2. how make the references in my .jsp files? e.i.
      <img src="????../myfolder/an_image.jpg"/>



        • 1. Re: Share resources beetwen portlets, how?
          Minh Hoang TO Novice

          Portlet is designed as deployable unit, so its dependen resources should be packed in the portlet application, RIGHT?





          About accessing to image stored externally, i have not tried but i think it 's doable in this way


          1. Get the PorltetApplication resource resolver from PortletRequestContext


          2. Get the InputStream to resource



          To get the PortletApplication resource resolver, we could do





          public PortletApplication(PortletConfig config) throws Exception
                portletConfig_ = config;
                PortletContext pcontext = config.getPortletContext();
                String contextName = pcontext.getPortletContextName();
                applicationId_ = contextName + "/" + config.getPortletName();


                ApplicationResourceResolver resolver = new ApplicationResourceResolver();
                resolver.addResourceResolver(new PortletResourceResolver(pcontext, "app:"));
                resolver.addResourceResolver(new PortletResourceResolver(pcontext, "par:"));


          As you could see, a default resource resolver  ApplicationResourceResolver is initiated/set on the portlet application


          public ApplicationResourceResolver()
                addResourceResolver(new FileResourceResolver());
                addResourceResolver(new ClasspathResourceResolver());


          This default resource resolver enables loading external resources

          • 2. Re: Share resources beetwen portlets, how?
            Trong Tran Master



            i find that this topic's problem is similar to http://community.jboss.org/thread/155344.


            Ideally your portlet war could serve as both portlet provider and resource provider. that is to use absolute path for resources in the portlet like :

            <img src="{portletContextPath}/myfolder/an_image.jpg"/>

            Notice that the portletContextPath can be taken out from RenderRequest.getContextPath() when rendering.