SWF-1238 Ensure the response is committed when rendering multiple fragments.

This commit is contained in:
Rossen Stoyanchev
2010-05-11 15:38:28 +00:00
parent ab26119353
commit 968014b4d7
3 changed files with 36 additions and 7 deletions

View File

@@ -17,7 +17,7 @@
</scp>
<sshexec host="spring02.managed.contegix.com" username="${username}" keyfile="${key.file}" passphrase="${passphrase}"
command="rm /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/2.0.x ; ln -s /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version} /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/2.0.x ; ln -s /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version}/spring-webflow-reference/ /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version}/reference" />
command="rm /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/2.1.x ; ln -s /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version} /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/2.1.x ; ln -s /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version}/spring-webflow-reference/ /opt/www/domains/springframework.org/www/htdocs/spring-webflow/docs/${bundle.version}/reference" />
<scp remoteToDir="${username}@spring02.managed.contegix.com:/opt/www/domains/springframework.org/www/htdocs/schema/faces"
keyfile="${key.file}" passphrase="${passphrase}" sftp="true" verbose="true">

View File

@@ -111,10 +111,11 @@ public class AjaxTilesView extends TilesView {
response);
addRuntimeAttributes(container, flattenedAttributeMap, request, response);
// initialize the session before rendering any fragments. Otherwise views that require the session which has
// not otherwise been initialized will fail to render
// request.getSession();
// response.flushBuffer();
if (fragmentsToRender.length > 1) {
// When rendering more than one fragment, flush the buffer in order to commit the response.
// With the response committed, Tiles does an include rather than forward.
response.flushBuffer();
}
for (int i = 0; i < fragmentsToRender.length; i++) {
Attribute attributeToRender = (Attribute) flattenedAttributeMap.get(fragmentsToRender[i]);

View File

@@ -1,6 +1,8 @@
package org.springframework.js.ajax.tiles2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
@@ -26,14 +28,14 @@ public class AjaxTilesViewTests extends TestCase {
private AjaxTilesView ajaxTilesView;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private MultipleIncludeUrlMockHttpServletResponse response;
private MockServletContext servletContext;
protected void setUp() throws Exception {
servletContext = new MockServletContext("/org/springframework/js/ajax/tiles2/");
request = new MockHttpServletRequest(servletContext);
response = new MockHttpServletResponse();
response = new MultipleIncludeUrlMockHttpServletResponse();
TilesConfigurer tc = new TilesConfigurer();
tc.setDefinitions(new String[] { "tiles-definitions.xml" });
@@ -112,6 +114,18 @@ public class AjaxTilesViewTests extends TestCase {
container.endContext(requestItems);
}
public void testRenderFragment_Multiple() throws Exception {
setupStaticWebApplicationContext();
request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE);
request.addParameter("fragments", "body,searchNavigation");
ajaxTilesView.setUrl("search");
ajaxTilesView.afterPropertiesSet();
ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response);
assertTrue("Multiple fragments should result in include, not forward", response.getIncludedUrls().size() == 2);
assertEquals("/WEB-INF/search.jsp", response.getIncludedUrls().get(0));
assertEquals("/WEB-INF/searchNavigation.jsp", response.getIncludedUrls().get(1));
}
public void testFlattenAttributeMap() throws Exception {
TilesRequestContextFactory tilesRequestContextFactory = new ServletTilesRequestContextFactory();
tilesRequestContextFactory.init(new HashMap());
@@ -136,4 +150,18 @@ public class AjaxTilesViewTests extends TestCase {
assertEquals("f2", fragments[1]);
assertEquals("f3", fragments[2]);
}
// Remove this class when no longer needed (http://jira.springframework.org/browse/SPR-7188)
private class MultipleIncludeUrlMockHttpServletResponse extends MockHttpServletResponse {
List includedUrls = new ArrayList();
public void setIncludedUrl(String includedUrl) {
super.setIncludedUrl(includedUrl);
includedUrls.add(includedUrl);
}
public List getIncludedUrls() {
return includedUrls;
}
}
}