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 20 package org.apache.myfaces.orchestra.conversation.jsf.components; 21 22 import java.io.IOException; 23 24 import javax.faces.component.UIComponentBase; 25 import javax.faces.context.FacesContext; 26 27 import org.apache.myfaces.orchestra.conversation.ConversationRequestParameterProvider; 28 import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils; 29 30 /** 31 * Embedded links will start a new conversation context. 32 * <p> 33 * Use this as the ancestor of any clickable links that should cause the new page to 34 * run within a totally new set of conversations. This really only makes sense when 35 * those links cause a new window to open. That new window then acts completely 36 * independently of the original window (as long as data is stored in conversations, 37 * not directly in the http session). 38 * <p> 39 * Normally, all urls within a view are rendered with a query parameter holding the 40 * current conversation context id, causing a later request to that url to use the 41 * same context as was used to render the original page. This tag causes this special 42 * query parameter to be omitted for all urls output by nested components. When any 43 * such url is invoked, the missing conversation context id then causes a new 44 * conversation context to be created. 45 */ 46 public class UISeparateConversationContext extends UIComponentBase 47 { 48 public static final String COMPONENT_FAMILY = "javax.faces.Component"; 49 public static final String COMPONENT_TYPE = "org.apache.myfaces.orchestra.SeparateConversationContext"; 50 51 public void encodeBegin(FacesContext context) throws IOException 52 { 53 super.encodeBegin(context); 54 55 // Stop appending the conversation context id to URLs. This means that a request using 56 // those urls will trigger a new conversation context rather than inheriting the one 57 // associated with this request. 58 ConversationRequestParameterProvider.setInSeparationMode(true); 59 } 60 61 public void encodeChildren(FacesContext context) throws IOException 62 { 63 try 64 { 65 RendererUtils.renderChildren(context, this); 66 } 67 finally 68 { 69 // Restore the original separation mode. Actually, we just assume here that 70 // the original value was false. There's no reason for anyone to ever nest 71 // UISeparateConversationContext components, and nothing else fiddles with 72 // this flag so false is a reasonable assumption. 73 // 74 // TODO: actually save the original value? 75 ConversationRequestParameterProvider.setInSeparationMode(false); 76 } 77 } 78 79 public boolean getRendersChildren() 80 { 81 return true; 82 } 83 84 public String getFamily() 85 { 86 return COMPONENT_FAMILY; 87 } 88 }