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

    Share resources beetwen portlets, how?

    fernando2010

      Hi

       

      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.
      ...etc
      <img src="????../myfolder/an_image.jpg"/>
      ...etc

       

      thanks

        • 1. Re: Share resources beetwen portlets, how?
          hoang_to

          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

           

          requestContext.getApplication().getResourceResolver();

           

           

          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:"));
                setResourceResolver(resolver);
             }

           

          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

            Hi,

             

            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.

            • 3. Re: Share resources beetwen portlets, how?
              fernando2010

              thank both for your comments.