View Javadoc

1   /*
2    * Copyright 2002-2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springbyexample.web.servlet.view.tiles2;
18  
19  import java.util.Map;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.springframework.webflow.execution.RequestContext;
25  import org.springframework.webflow.execution.RequestContextHolder;
26  import org.springframework.webflow.execution.View;
27  
28  /**
29   * <p>If the request isn't an AJAX request, <code>DynamicTilesView</code> 
30   * will handle the request.  Otherwise it is expected that an AJAX 
31   * view render will be next in the chain and can handle the request.</p>
32   * 
33   * <p><strong>Note</strong>: All code is copied from <code>AjaxDynamicTilesView</code> (giving author credit to original author).  
34   * Necessary to duplicate logic since <code>getRenderFragments</code> is protected, so no way to delegate to 
35   * the original code.</p>
36   * 
37   * @author Jeremy Grelle
38   */
39  public class FlowAjaxDynamicTilesView extends AjaxDynamicTilesView {
40  
41      /**
42       * <p>Gets rendered fragments.</p>
43       * 
44       * <p><strong>Note</strong>: Copied from <code>FlowAjaxTilesView</code>.</p>
45       */
46      protected String[] getRenderFragments(Map model, HttpServletRequest request, HttpServletResponse response) {
47          RequestContext context = RequestContextHolder.getRequestContext();
48          
49          if (context == null) {
50              return super.getRenderFragments(model, request, response);
51          } else {
52              String[] fragments = (String[]) context.getFlashScope().get(View.RENDER_FRAGMENTS_ATTRIBUTE);
53              if (fragments == null) {
54                  return super.getRenderFragments(model, request, response);
55              }
56              return fragments;
57          }
58      }
59      
60  }