1 16 17 package org.springframework.web.jsf; 18 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 22 import javax.faces.context.FacesContext; 23 import javax.faces.event.PhaseEvent; 24 import javax.faces.event.PhaseId; 25 import javax.faces.event.PhaseListener; 26 27 import org.springframework.beans.factory.BeanFactoryUtils; 28 import org.springframework.beans.factory.ListableBeanFactory; 29 import org.springframework.web.context.WebApplicationContext; 30 31 64 public class DelegatingPhaseListenerMulticaster implements PhaseListener { 65 66 public PhaseId getPhaseId() { 67 return PhaseId.ANY_PHASE; 68 } 69 70 public void beforePhase(PhaseEvent event) { 71 Collection listeners = getDelegates(event.getFacesContext()); 72 Iterator it = listeners.iterator(); 73 while (it.hasNext()) { 74 PhaseListener listener = (PhaseListener) it.next(); 75 listener.beforePhase(event); 76 } 77 } 78 79 public void afterPhase(PhaseEvent event) { 80 Collection listeners = getDelegates(event.getFacesContext()); 81 Iterator it = listeners.iterator(); 82 while (it.hasNext()) { 83 PhaseListener listener = (PhaseListener) it.next(); 84 listener.afterPhase(event); 85 } 86 } 87 88 89 97 protected Collection getDelegates(FacesContext facesContext) { 98 ListableBeanFactory bf = getBeanFactory(facesContext); 99 return BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, PhaseListener.class, true, false).values(); 100 } 101 102 111 protected ListableBeanFactory getBeanFactory(FacesContext facesContext) { 112 return getWebApplicationContext(facesContext); 113 } 114 115 122 protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) { 123 return FacesContextUtils.getRequiredWebApplicationContext(facesContext); 124 } 125 126 } 127 | Popular Tags |