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.custom.conversation;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponentBase;
24  import javax.faces.context.FacesContext;
25  
26  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
27  
28  /**
29   * Separates the current context from the children. e.g. commandLinks will start a 
30   * new conversation context
31   * 
32   * separate the current context from the to be rendered children.
33   * E.g. when you render commandLinks they will start a new conversationContext
34   * 
35   * @JSFComponent
36   *   name = "s:separateConversationContext"
37   *   tagClass = "org.apache.myfaces.custom.conversation.SeparateConversationContextTag"
38   *   
39   * @author imario@apache.org
40   */
41  public class UISeparateConversationContext extends UIComponentBase
42  {
43      public static final String COMPONENT_FAMILY = "javax.faces.Component";
44      public static final String COMPONENT_TYPE = "org.apache.myfaces.SeparateConversationContext";
45  
46      private final static ThreadLocal inSeperationMode = new ThreadLocal();
47      
48      public static void setInSeparationMode(boolean seperationMode)
49      {
50          inSeperationMode.set(seperationMode?Boolean.TRUE:Boolean.FALSE);
51      }
52  
53      public static boolean isInSeparationMode()
54      {
55          return Boolean.TRUE.equals(inSeperationMode.get());
56      }
57      
58      public void encodeBegin(FacesContext context) throws IOException
59      {
60          super.encodeBegin(context);
61  
62          setInSeparationMode(true);
63      }
64  
65      public void encodeChildren(FacesContext context) throws IOException
66      {
67          try
68          {
69              RendererUtils.renderChildren(context, this);
70          }
71          finally
72          {
73              setInSeparationMode(false);
74          }
75      }
76  
77      public boolean getRendersChildren()
78      {
79          return true;
80      }
81      
82      public String getFamily()
83      {
84          return COMPONENT_FAMILY;
85      }
86  }