View Javadoc

1   /*
2    * $Id: PartialRenderingContextFactory.java,v 1.1 2010/06/11 08:35:37 oeuillot Exp $
3    */
4   package org.rcfaces.core.partialRendering;
5   
6   import java.util.Map;
7   
8   import javax.faces.context.FacesContext;
9   
10  import org.rcfaces.core.internal.util.PartialRenderingContextImpl;
11  
12  /**
13   * 
14   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
15   * @version $Revision: 1.1 $ $Date: 2010/06/11 08:35:37 $
16   */
17  public class PartialRenderingContextFactory {
18      private static final String PARTIAL_RENDERING_CONTEXT_PROPERTY = "org.rcfaces.core.PARTIAL_RENDERING_CONTEXT";
19  
20      public static IPartialRenderingContext get() {
21          return get(null);
22      }
23  
24      public static IPartialRenderingContext get(FacesContext facesContext) {
25          if (facesContext == null) {
26              facesContext = FacesContext.getCurrentInstance();
27          }
28  
29          Map requestMap = facesContext.getExternalContext().getRequestMap();
30  
31          IPartialRenderingContext partialRenderingContext = (IPartialRenderingContext) requestMap
32                  .get(PARTIAL_RENDERING_CONTEXT_PROPERTY);
33          if (partialRenderingContext != null) {
34              return partialRenderingContext;
35          }
36  
37          partialRenderingContext = new PartialRenderingContextImpl(facesContext);
38  
39          requestMap.put(PARTIAL_RENDERING_CONTEXT_PROPERTY,
40                  partialRenderingContext);
41  
42          return partialRenderingContext;
43      }
44  }