public static ApplicationContext getWebApplicationContext ( PortletRequest request , PortletContext portletContext ) throws IllegalStateException { PortletApplicationContext portletApplicationContext = ( PortletApplicationContext ) request . getAttribute ( ContribDispatcherPortlet . PORTLET_APPLICATION_CONTEXT_ATTRIBUTE ) ; if ( portletApplicationContext != null ) { return portletApplicationContext ; } if ( portletContext == null ) { throw new IllegalStateException ( "No PortletApplicationContext found: not in a DispatcherPortlet request?" ) ; } portletApplicationContext = PortletApplicationContextUtils2 . getPortletApplicationContext ( portletContext ) ; if ( portletApplicationContext != null ) { return portletApplicationContext ; } return PortletApplicationContextUtils . getRequiredWebApplicationContext ( portletContext ) ; }
Look for the PortletApplicationContext associated with the DispatcherPortlet that has initiated request processing for the global portlet context if none was found associated with the current request and for the global context if no global portlet context was found . This method is useful to allow components outside the framework such as JSP tag handlers to access the most specific application context available .