1 16 package org.springframework.webflow.executor.jsf; 17 18 import javax.faces.application.NavigationHandler; 19 import javax.faces.context.FacesContext; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.springframework.web.jsf.DecoratingNavigationHandler; 24 import org.springframework.webflow.context.ExternalContext; 25 import org.springframework.webflow.core.collection.MutableAttributeMap; 26 import org.springframework.webflow.definition.FlowDefinition; 27 import org.springframework.webflow.definition.registry.FlowDefinitionLocator; 28 import org.springframework.webflow.execution.FlowExecution; 29 import org.springframework.webflow.execution.FlowExecutionFactory; 30 import org.springframework.webflow.execution.ViewSelection; 31 import org.springframework.webflow.executor.support.FlowExecutorArgumentExtractor; 32 33 70 public class FlowNavigationHandler extends DecoratingNavigationHandler { 71 72 75 protected final Log logger = LogFactory.getLog(getClass()); 76 77 81 private FlowExecutorArgumentExtractor argumentExtractor = new FlowNavigationHandlerArgumentExtractor(); 82 83 86 public FlowNavigationHandler() { 87 super(); 88 } 89 90 96 public FlowNavigationHandler(NavigationHandler originalNavigationHandler) { 97 super(originalNavigationHandler); 98 } 99 100 103 public FlowExecutorArgumentExtractor getArgumentExtractor() { 104 return argumentExtractor; 105 } 106 107 110 public void setArgumentExtractor(FlowExecutorArgumentExtractor argumentExtractor) { 111 this.argumentExtractor = argumentExtractor; 112 } 113 114 public void handleNavigation(FacesContext facesContext, String fromAction, String outcome, 115 NavigationHandler originalNavigationHandler) { 116 JsfExternalContext context = new JsfExternalContext(facesContext, fromAction, outcome); 117 if (FlowExecutionHolderUtils.isFlowExecutionRestored(facesContext)) { 118 if (argumentExtractor.isEventIdPresent(context)) { 121 String eventId = argumentExtractor.extractEventId(context); 123 FlowExecutionHolder holder = FlowExecutionHolderUtils.getFlowExecutionHolder(facesContext); 124 ViewSelection selectedView = holder.getFlowExecution().signalEvent(eventId, context); 125 holder.setViewSelection(selectedView); 126 holder.markNeedsSave(); 127 } 128 } 129 else { 130 if (argumentExtractor.isFlowIdPresent(context)) { 133 String flowId = argumentExtractor.extractFlowId(context); 135 FlowDefinition flowDefinition = getLocator(context).getFlowDefinition(flowId); 136 FlowExecution flowExecution = getFactory(context).createFlowExecution(flowDefinition); 137 FlowExecutionHolder holder = new FlowExecutionHolder(flowExecution); 138 FlowExecutionHolderUtils.setFlowExecutionHolder(holder, facesContext); 139 ViewSelection selectedView = flowExecution.start(createInput(flowExecution, context), context); 140 holder.setViewSelection(selectedView); 141 holder.markNeedsSave(); 142 } 143 else { 144 originalNavigationHandler.handleNavigation(facesContext, fromAction, outcome); 146 } 147 } 148 } 149 150 private FlowDefinitionLocator getLocator(JsfExternalContext context) { 151 return FlowFacesUtils.getDefinitionLocator(context.getFacesContext()); 152 } 153 154 private FlowExecutionFactory getFactory(JsfExternalContext context) { 155 return FlowFacesUtils.getExecutionFactory(context.getFacesContext()); 156 } 157 158 165 protected MutableAttributeMap createInput(FlowExecution flowExecution, ExternalContext context) { 166 return null; 167 } 168 } | Popular Tags |