view postback

mvc binding work
This commit is contained in:
Keith Donald
2008-03-20 02:10:14 +00:00
parent 6a62e98396
commit 07ad145106
7 changed files with 85 additions and 40 deletions

View File

@@ -58,19 +58,6 @@ public class JsfView implements View {
this.context = context;
}
public boolean eventSignaled() {
return context.getExternalContext().getRequestMap().contains(EVENT_KEY);
}
public Event getEvent() {
String eventId = (String) context.getExternalContext().getRequestMap().get(EVENT_KEY);
return new Event(this, eventId);
}
public UIViewRoot getViewRoot() {
return this.viewRoot;
}
/**
* This implementation performs the standard duties of the JSF RENDER_RESPONSE phase.
*/
@@ -92,6 +79,23 @@ public class JsfView implements View {
}
}
public void postback() {
// TODO - implement Postback JSF lifecycle
}
public boolean eventSignaled() {
return context.getExternalContext().getRequestMap().contains(EVENT_KEY);
}
public Event getEvent() {
String eventId = (String) context.getExternalContext().getRequestMap().get(EVENT_KEY);
return new Event(this, eventId);
}
public UIViewRoot getViewRoot() {
return this.viewRoot;
}
public String toString() {
return "[JSFView = '" + viewId + "']";
}

View File

@@ -175,6 +175,7 @@ public class ViewState extends TransitionableState {
public void resume(RequestControlContext context) {
restoreVariables(context);
View view = viewFactory.getView(context);
view.postback();
if (view.eventSignaled()) {
Event event = view.getEvent();
if (logger.isDebugEnabled()) {

View File

@@ -60,6 +60,16 @@ public class ActionExecutingViewFactory implements ViewFactory {
this.context = context;
}
public void render() {
if (action != null) {
ActionExecutor.execute(action, context);
}
}
public void postback() {
}
public boolean eventSignaled() {
return context.getExternalContext().getRequestParameterMap().contains("_eventId");
}
@@ -68,11 +78,5 @@ public class ActionExecutingViewFactory implements ViewFactory {
return new Event(this, context.getExternalContext().getRequestParameterMap().get("_eventId"));
}
public void render() {
if (action != null) {
ActionExecutor.execute(action, context);
}
}
}
}

View File

@@ -38,14 +38,20 @@ public interface View {
public void render() throws IOException;
/**
* Was a user event signaled on this view in this request?
* Execute the view postback lifecycle. This typically results in a view model binding and validation.
*/
public void postback();
/**
* Returns true if an event occurred the flow system should handle.
* @return true if yes, false otherwise
*/
public boolean eventSignaled();
/**
* Get the user event signaled on this view in this request.
* @return the user event
* Get the user event the flow should handle. Returns an event object when {@link #eventSignaled()} returns true.
* Returns null otherwise
* @return the event, or null if there is no event for the flow system to handle
*/
public Event getEvent();

View File

@@ -24,13 +24,16 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.binding.expression.Expression;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.format.FormatterRegistry;
import org.springframework.binding.mapping.MappingResults;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.util.ClassUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.JstlView;
@@ -57,8 +60,11 @@ public class MvcViewFactoryCreator implements ViewFactoryCreator, ApplicationCon
private static final boolean jstlPresent = ClassUtils.isPresent("javax.servlet.jsp.jstl.fmt.LocalizationContext");
private static final boolean springSecurityPresent = ClassUtils
.isPresent("org.springframework.security.context.SecurityContextHolder");
// TODO
private ExpressionParser expressionParser;
// TODO
private FormatterRegistry formatterRegistry;
private List viewResolvers;
@@ -187,6 +193,27 @@ public class MvcViewFactoryCreator implements ViewFactoryCreator, ApplicationCon
this.context = context;
}
public void render() {
Map model = new HashMap();
model.putAll(context.getConversationScope().union(context.getFlowScope()).union(context.getFlashScope())
.union(context.getRequestScope()).asMap());
exposeBindingModel(model);
model.put("flowRequestContext", context);
model.put("flowExecutionKey", context.getFlowExecutionContext().getKey().toString());
model.put("flowExecutionUrl", context.getFlowExecutionUrl());
model.put("currentUser", context.getExternalContext().getCurrentUser());
try {
view.render(model, (HttpServletRequest) context.getExternalContext().getNativeRequest(),
(HttpServletResponse) context.getExternalContext().getNativeResponse());
} catch (Exception e) {
throw new IllegalStateException("Exception rendering view", e);
}
}
public void postback() {
// TODO implement me with real data binding behavior
}
public boolean eventSignaled() {
determineEventId(context);
return eventId != null;
@@ -196,21 +223,16 @@ public class MvcViewFactoryCreator implements ViewFactoryCreator, ApplicationCon
return new Event(this, eventId, context.getRequestParameters().asAttributeMap());
}
public void render() {
Map model = new HashMap();
model.putAll(context.getConversationScope().union(context.getFlowScope()).union(context.getFlashScope())
.union(context.getRequestScope()).asMap());
model.put("flowRequestContext", context);
model.put("flowExecutionKey", context.getFlowExecutionContext().getKey().toString());
model.put("flowExecutionUrl", context.getFlowExecutionUrl());
if (springSecurityPresent && !model.containsKey("currentUser")) {
model.put("currentUser", SecurityContextHolder.getContext().getAuthentication());
}
try {
view.render(model, (HttpServletRequest) context.getExternalContext().getNativeRequest(),
(HttpServletResponse) context.getExternalContext().getNativeResponse());
} catch (Exception e) {
throw new IllegalStateException("Exception rendering view", e);
private void exposeBindingModel(Map model) {
Expression boundObjectExpr = (Expression) context.getCurrentState().getAttributes().get("model");
if (boundObjectExpr != null) {
Object boundObject = boundObjectExpr.getValue(context);
// TODO
BindingModel bindingModel = new BindingModel(boundObject, null, null, context.getMessageContext());
MappingResults bindResults = (MappingResults) context.getRequestScope().get(
boundObjectExpr.getExpressionString() + "MappingResults");
bindingModel.setMappingResults(bindResults);
model.put(BindingResult.MODEL_KEY_PREFIX + boundObjectExpr.getExpressionString(), model);
}
}

View File

@@ -100,6 +100,10 @@ class MockViewFactoryCreator implements ViewFactoryCreator {
return context.getRequestParameters().contains("_eventId");
}
public void postback() {
// TODO - implement me as appropriate for a test environment
}
public Event getEvent() {
return new Event(this, context.getRequestParameters().get("_eventId"));
}

View File

@@ -37,6 +37,10 @@ public class StubViewFactory implements ViewFactory {
context.getFlowScope().put("renderCalled", Boolean.TRUE);
}
public void postback() {
}
public boolean eventSignaled() {
return context.getExternalContext().getRequestParameterMap().contains("_eventId");
}