title: Liferay: AJAX call in configuration mode impossible?
body: <p>Is it possible to use AJAX in configuration mode?</p>
  
  <p>I am using custom class extending DefaultConfigurationAction to customize my portlet in the configuration mode. I override processAction and render methods, which work OK, but when I try to implement serveResource method, it is never called (returned status is 200 OK, but no data is fetched and no debug message is printed to the Liferay console). </p>
  
  <p>My code for serveResource method:</p>
  
  <pre><code>public class TestConfigurationController extends DefaultConfigurationAction {
  ...
      @Override
      public void serveResource(PortletConfig portletConfig, ResourceRequest resourceRequest,
              ResourceResponse resourceResponse) throws PortletException, IOException, Exception {
          String resourceID = resourceRequest.getResourceID();
          System.out.println("Resource id=" + resourceID
                  + " in TestConfigurationController.serveResource().");         // this message never prints, method is not invoked
          if (IMG_EDIT_ADD_NEW.equals(resourceID)) {
              // more code
              include(EDIT_NEW_IMAGE, context, resourceRequest, resourceResponse);    // uses PortletRequestDispatcher, returns a JSPF fragment
          } else {
              super.serveResource(portletConfig, resourceRequest, resourceResponse);
          }
      }
  }
  </code></pre>
  
  <p>I tried all options on the JS side, including both JQuery and AUI. Here is relevant code in configuration.jsp:</p>
  
  <pre><code>&lt;portlet:resourceURL var="newImageJsp" id = "&lt;%=IMG_EDIT_ADD_NEW%&gt;"&gt;
  &lt;/portlet:resourceURL&gt;
  
  &lt;aui:button name="addNewImage" type="button" value="${addImage}"/&gt;
  &lt;div id="&lt;portlet:namespace/&gt;newImageContainer"&gt;
      &lt;aui:field-wrapper name="newImageContainer" label="${addImage}"&gt;
      &lt;/aui:field-wrapper&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript" charset="utf-8"&gt;
  // Even this simple AUI AJAX call does not trigger serveResource method!
  
  //    AUI().ready('aui-base', 'aui-module', 'node', 'aui-io-request', function (A) {
  //        A.io.request('&lt;%=newImageJsp.toString()%&gt;');
  //    });
  
      jQuery(document).ready(function () {
          jQuery('#&lt;portlet:namespace/&gt;addNewImage').on('click', function (event) {
              console.log('addNewImage clicked, url: ${newImageJsp}');                   // returns correct url
              jQuery.ajax({
                  dataType: 'text',
                  url: '${newImageJsp}',
                  success: function (data, status) {
                      console.log('returned resource: ' + data);          // returns empty string
                      console.log('returned status: ' + status);            // returns 200 OK, which is also in the Firebunetwork panel
                      $('#&lt;portlet:namespace/&gt;newImageContainer').html(data);
                  }
              });
              return false;
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Debugging in console revealed, JS is working fine, function was called and returned status was 200 OK. However, returned data was empty and serveResource method on the server was never called. </p>
  
  <p>As an experiment, I also tried to set </p>
  
  <pre><code>&lt;aui:form action="${newImageJsp}" method="get" name="fm1"&gt;
  </code></pre>
  
  <p>which didn't call the serveResource method either, instead, it returned the view.jsp of the configured portlet.</p>
  
  <p>And finally my configuration, which is exactly as in this <a href="https://stackoverflow.com/questions/19853798/creating-a-liferay-portlet-configuration-page">working case</a>: </p>
  
  <p>portlet.xml:</p>
  
  <pre><code>&lt;portlet&gt;
          &lt;portlet-name&gt;test-portlet&lt;/portlet-name&gt;
          &lt;portlet-class&gt;org.springframework.web.portlet.DispatcherPortlet&lt;/portlet-class&gt;
          &lt;init-param&gt;
              &lt;name&gt;contextConfigLocation&lt;/name&gt;
              &lt;value&gt;/WEB-INF/spring-context/portlet/test-portlet.xml&lt;/value&gt;
                  &lt;/init-param&gt;
                  &lt;init-param&gt;
                      &lt;name&gt;config-template&lt;/name&gt;
                      &lt;value&gt;/WEB-INF/jsp/carousel/configuration.jsp&lt;/value&gt;
                  &lt;/init-param&gt;
          &lt;expiration-cache&gt;0&lt;/expiration-cache&gt;
          &lt;supports&gt;
              &lt;mime-type&gt;text/html&lt;/mime-type&gt;
                          &lt;portlet-mode&gt;view&lt;/portlet-mode&gt;
                          &lt;portlet-mode&gt;edit&lt;/portlet-mode&gt;
          &lt;/supports&gt;
          &lt;portlet-info&gt;
              &lt;title&gt;Test&lt;/title&gt;
          &lt;/portlet-info&gt;
      &lt;/portlet&gt;
  </code></pre>
  
  <p>and liferay-portlet.xml:</p>
  
  <pre><code>&lt;liferay-portlet-app&gt;
      &lt;portlet&gt;
          &lt;portlet-name&gt;test-portlet&lt;/portlet-name&gt;
          &lt;icon&gt;/icon.png&lt;/icon&gt;
                  &lt;configuration-action-class&gt;com.test.TestConfigurationController&lt;/configuration-action-class&gt;
                  &lt;requires-namespaced-parameters&gt;false&lt;/requires-namespaced-parameters&gt;
                  &lt;ajaxable&gt;true&lt;/ajaxable&gt;
          &lt;header-portlet-css&gt;/css/main.css&lt;/header-portlet-css&gt;
                  &lt;header-portlet-javascript&gt;/js/jquery-1.11.3.min.js&lt;/header-portlet-javascript&gt;
          &lt;header-portlet-javascript&gt;/js/main.js&lt;/header-portlet-javascript&gt;
      &lt;/portlet&gt;
  &lt;/liferay-portlet-app&gt;
  </code></pre>
  
  <p>So, it seems I have a similar problem, as this <a href="https://stackoverflow.com/questions/33584951/ajax-not-working-in-the-portlet-configuration-jsp-page-liferay-6-2">unresolved issue</a> </p>
  
  <p>I was thinking, that maybe it is the window state? Configuration mode always uses 'pop-up', but in all examples I only found AJAX calls using 'normal' window state. Maybe that is the problem? Is it even possible to make asynchronous JSPF loadings in pop-up mode? And even in configuration window? I never found a working example of use of AJAX in <strong>configuration mode</strong> and official Liferay only has examples for view mode.</p>
  
  <p>Last but not least, I tested the same code in view.jsp for view mode and the resource serving method in TestViewController was called OK. I used Spring annotations here (@ResourceMapping). So the problem must be with Liferay and configuration mode. A bug maybe?</p>
  
  <p>Thank you!</p>