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 *
36 * @author imario@apache.org
37 */
38 public class UISeparateConversationContext extends UIComponentBase
39 {
40 public static final String COMPONENT_FAMILY = "javax.faces.Component";
41 public static final String COMPONENT_TYPE = "org.apache.myfaces.SeparateConversationContext";
42
43 private final static ThreadLocal inSeperationMode = new ThreadLocal();
44
45 public static void setInSeparationMode(boolean seperationMode)
46 {
47 inSeperationMode.set(seperationMode?Boolean.TRUE:Boolean.FALSE);
48 }
49
50 public static boolean isInSeparationMode()
51 {
52 return Boolean.TRUE.equals(inSeperationMode.get());
53 }
54
55 public void encodeBegin(FacesContext context) throws IOException
56 {
57 super.encodeBegin(context);
58
59 setInSeparationMode(true);
60 }
61
62 public void encodeChildren(FacesContext context) throws IOException
63 {
64 try
65 {
66 RendererUtils.renderChildren(context, this);
67 }
68 finally
69 {
70 setInSeparationMode(false);
71 }
72 }
73
74 public boolean getRendersChildren()
75 {
76 return true;
77 }
78
79 public String getFamily()
80 {
81 return COMPONENT_FAMILY;
82 }
83 }