title: Get Portlet Application Context from another portlet (Liferay + Spring)
body: <p>I want to create a portlet (let's call it 'Action Manager') to list all the action methods (using spring Annotation <code>@ActionMapping</code>) from all the portlets in the same page as my Action Manager portlet.</p>
  
  <p>All my other portlets are using <code>ParameterHandlerMapping</code> to map the incoming requests to the appropriate Controller</p>
  
  <pre><code>&lt;bean id="parameterHandlerMapping" class="org.springframework.web.portlet.handler.ParameterHandlerMapping"&gt;
      &lt;property name="defaultHandler" ref="Controller1" /&gt;
      &lt;property name="parameterName" value="control" /&gt;
      &lt;property name="parameterMap"&gt;
          &lt;map&gt;
              &lt;entry key="1" value-ref="Controller1" /&gt;
              &lt;entry key="2" value-ref="Controller2" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>So my intention is to get all the portlets in my current page (I'm already doing that) and try to get the <code>parameterHandlerMapping</code> bean from each portlet and, from there, get its controller names (<code>Controller1</code>, <code>Controller2</code>) which I will later used to get the <code>@ActionMapping</code> annotated methods.</p>
  
  <p>Is it possible to access each portlet "private" context and retrieve the <code>parameterHandlerMapping</code> bean?</p>
  
  <p>I'm currently stuck with this:</p>
  
  <pre><code>PortletBag portletBag = PortletBagPool.get(portlet.getPortletId());
      if (portletBag != null) {
          ServletContext servletContext = portletBag.getServletContext();
          ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
          ParameterHandlerMapping parameterHandlerMapping = (ParameterHandlerMapping) ctx.getBean(ParameterHandlerMapping.class);
  
  }
  </code></pre>
  
  <p>This results in an exception being thrown because there's no matching bean in the application context. I tried to get it by the bean's name and the result is pretty much the same.</p>
  
  <p>I also got a list of all the beans present in the context using</p>
  
  <pre><code>String beanNames[] = ctx.getBeanNamesForType(Object.class);
  for (String beanName : beanNames) {
      System.out.println(beanName);
  }
  </code></pre>
  
  <p>and the <code>parameterHandlerMapping</code> bean is not present.</p>
  
  <p>It's my understanding that each portlet has its own <code>parameterHandlerMapping</code> bean, so i guess  the <code>ctx</code> i'm getting is the "global" context and not the portlet's own "private" context where the <code>parameterHandlerMapping</code> bean is defined.</p>
  
  <p>If I'm correct and I'm getting the "global" context, is there a way to get a portlet's "private" context based on its portletId? Is it even possible to do what I want?</p>
  
  <p>Thank you for all your help</p>