View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets;
20  
21  import javax.faces.FactoryFinder;
22  import javax.faces.component.UIViewRoot;
23  import javax.faces.component.visit.VisitContextFactory;
24  import javax.faces.context.FacesContext;
25  import javax.faces.render.RenderKitFactory;
26  import org.apache.myfaces.shared.view.ViewDeclarationLanguageBase;
27  
28  /**
29   *
30   * @author Leonardo Uribe
31   */
32  public abstract class FaceletViewDeclarationLanguageBase extends ViewDeclarationLanguageBase
33  {
34      /**
35       * UIViewRoot attribute to check if the dynamic components in a view should be refreshed under a transient build
36       */
37      private static final String DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD = "oam.vf.DCRTB";
38      
39      private static final String DYNAMIC_COMPONENT_NEEDS_REFRESH = "oam.vf.DC_NEEDS_REFRESH";
40      
41      private VisitContextFactory _visitContextFactory = null;
42      
43      private RenderKitFactory _renderKitFactory = null;
44  
45      protected VisitContextFactory getVisitContextFactory()
46      {
47          if (_visitContextFactory == null)
48          {
49              _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
50          }
51          return _visitContextFactory;
52      }
53      
54      public static boolean isDynamicComponentRefreshTransientBuildActive(FacesContext facesContext)
55      {
56          if (facesContext.getViewRoot() == null)
57          {
58              return false;
59          }
60          return Boolean.TRUE.equals(facesContext.getViewRoot().getAttributes().get(
61                  DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD));
62      }
63      
64      public static boolean isDynamicComponentRefreshTransientBuildActive(FacesContext facesContext, UIViewRoot view)
65      {
66          return Boolean.TRUE.equals(view.getAttributes().get(
67                  DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD));
68      }
69      
70      public static void activateDynamicComponentRefreshTransientBuild(FacesContext facesContext)
71      {
72          if (!isDynamicComponentRefreshTransientBuildActive(facesContext))
73          {
74              facesContext.getViewRoot().getAttributes().put(
75                      DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD, Boolean.TRUE);
76          }
77      }
78      
79      public static boolean isDynamicComponentNeedsRefresh(FacesContext context)
80      {
81          return Boolean.TRUE.equals(context.getAttributes().get(DYNAMIC_COMPONENT_NEEDS_REFRESH));
82      }
83  
84      public static void dynamicComponentNeedsRefresh(FacesContext context)
85      {
86          context.getAttributes().put(DYNAMIC_COMPONENT_NEEDS_REFRESH, Boolean.TRUE);
87      }
88      
89      public static void resetDynamicComponentNeedsRefreshFlag(FacesContext context)
90      {
91          context.getAttributes().put(DYNAMIC_COMPONENT_NEEDS_REFRESH, Boolean.FALSE);
92      }
93   
94      protected RenderKitFactory getRenderKitFactory()
95      {
96          if (_renderKitFactory == null)
97          {
98              _renderKitFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
99          }
100         return _renderKitFactory;
101     }
102 
103 }