This text file describes one possible workaround to . The root cause of the problem, like most Mojarra+Virtual Server problems, is the invalidity of the assumption that there is always just one ServletContext per app per VM. In the case of N virtual servers, there are N ServletContext instances (and attendent lifecycle listener calls) per app per VM. This is why the PhaseListeners are invoked seven times for a seven node virtual server scenario. The Fix: The fix for , which *did* go into Mojarra 2.1.0-b11 as the reporter states, involved the creation of a silly little container object that ensured the expected cardinality was maintained, even in the case of virtual servers. I have copied/pasted that silly little container object into an existing automated test in Mojarra. To see the source, check out Mojarra per the instructions at and look at the tags for the branch or trunk . The path to the test in the source code is . Note the faces-config includes a custom lifecycle declaration. com.sun.faces.systest.LifecycleFactoryImpl Here is the source for that class. 8<------------------------------------------- /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces.systest; import java.util.Collections; import javax.faces.FacesException; import javax.faces.lifecycle.Lifecycle; import javax.faces.lifecycle.LifecycleFactory; import java.util.Iterator; public class LifecycleFactoryImpl extends LifecycleFactory { private static final String KEY = LifecycleFactoryImpl.class.getName(); public LifecycleFactoryImpl(LifecycleFactory previous) { try { SingletonStore store = new SingletonStore(KEY); store.putSingletonReference(previous); Lifecycle newLifecycle = new NewLifecycle("com.sun.faces.systest.NewLifecycle"); previous.addLifecycle("com.sun.faces.systest.NewLifecycle", newLifecycle); newLifecycle = new NewLifecycle("com.sun.faces.systest.AlternateLifecycle"); previous.addLifecycle("com.sun.faces.systest.AlternateLifecycle", newLifecycle); } catch (Throwable e) { throw new FacesException(e); } } public void addLifecycle(String lifecycleId, Lifecycle lifecycle) { SingletonStore store = new SingletonStore(KEY); LifecycleFactory previous = store.getReferenceToSingleton(); if (null != previous) { previous.addLifecycle(lifecycleId, lifecycle); } } public Lifecycle getLifecycle(String lifecycleId) { SingletonStore store = new SingletonStore(KEY); LifecycleFactory previous = store.getReferenceToSingleton(); Lifecycle result = null; if (null != previous) { result = previous.getLifecycle(lifecycleId); } else { System.out.println("getLifecycle(): How is this happening?"); } return result; } public Iterator getLifecycleIds() { Iterator result = Collections.EMPTY_LIST.iterator(); SingletonStore store = new SingletonStore(KEY); LifecycleFactory previous = store.getReferenceToSingleton(); if (null != previous) { result = previous.getLifecycleIds(); } else { System.out.println("getLifecycleIds(): How is this happening?"); } return result; } } 8<------------------------------------------- Note, that the "NewLifecycle" part of the code is related to the test, and not related to the workaround. Now, the code for the SingletonStore. 8<------------------------------------------- /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces.systest; import java.util.Collections; import java.util.Map; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; /* * This class is responsible for storing an instance of S * in a ServletContext instance such that the instance is a singleton * within that ServletContext instance. * */ class SingletonStore { // private final String key; private final String keyForKey; private Map appMap; // // private static final String KEY_BASE = SingletonStore.class.getName(); // // public SingletonStore(String singletonKey) { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext extContext = facesContext.getExternalContext(); if (null != facesContext) { appMap = extContext.getApplicationMap(); } else { assert(false); appMap = Collections.emptyMap(); } Object context = extContext.getContext(); keyForKey = KEY_BASE + singletonKey; String candidateKey = (String) appMap.get(keyForKey); // Is this the first time that this kind of singleton has been created // for this ServletContext instance or any wrapped instance? if (null == candidateKey) { // if so, create the key... this.key = singletonKey + context.hashCode(); appMap.put(keyForKey, this.key); } else { this.key = candidateKey; } } // // static Object removeSingletonReference(ExternalContext extContext, String singletonKey) { Object result = null; Map map = extContext.getApplicationMap(); String keyForKey = KEY_BASE + singletonKey; String keyVal = (String) map.get(keyForKey); result = map.remove(keyVal); map.remove(keyForKey); return result; } static void removeSingletonReference(ServletContext context, String singletonKey) { String keyForKey = KEY_BASE + singletonKey; String keyVal = (String) context.getAttribute(keyForKey); context.removeAttribute(keyVal); context.removeAttribute(keyForKey); } static Object getReferenceToSingleton(ExternalContext extContext, String singletonKey) { Object result = null; Map map = extContext.getApplicationMap(); String keyForKey = KEY_BASE + singletonKey; String keyVal = (String) map.get(keyForKey); if (null != keyVal) { result = map.get(keyVal); } return result; } static Object getReferenceToSingleton(ServletContext context, String singletonKey) { Object result = null; String keyForKey = KEY_BASE + singletonKey; String keyVal = (String) context.getAttribute(keyForKey); if (null != keyVal) { result = context.getAttribute(keyVal); } return result; } // // S getReferenceToSingleton() { S result = (S) appMap.get(key); return result; } S removeSingletonReference() { S result = null; if (null != appMap) { appMap.remove(keyForKey); result = (S) appMap.remove(key); } return result; } void putSingletonReference(S instance) { appMap.put(key, instance); } // } 8<------------------------------------------- I think the static methods are unnecessary, but they came along for the ride when I cut and pasted it from Mojarra.