handling recursive transitions for view-states

This commit is contained in:
Keith Donald
2008-07-30 14:37:01 +00:00
parent 4d6ed71933
commit 180e685c81
8 changed files with 44 additions and 23 deletions

View File

@@ -39,7 +39,7 @@
<on-entry>
<evaluate expression="interview.getNextQuestionSet()" result="viewScope.questionSet" />
</on-entry>
<transition on="submitAnswers">
<transition on="submitAnswers" to="moreAnswersNeeded">
<evaluate expression="interview.recordAnswers(questionSet)" />
</transition>
</view-state>

View File

@@ -9,16 +9,21 @@
<on-render>
<evaluate expression="bookingService.findBookings(currentUser.name)" result="viewScope.bookings" result-type="dataModel" />
</on-render>
<transition on="search" to="reviewHotels">
<evaluate expression="searchCriteria.resetPage()" />
</transition>
<transition on="search" />
<transition on="cancelBooking">
<evaluate expression="bookingService.cancelBooking(bookings.selectedRow)" />
<render fragments="bookingsFragment" />
</transition>
</view-state>
<view-state id="reviewHotels">
<action-state id="resetPage">
<evaluate expression="searchCriteria.resetPage()" />
<transition on="success" to="enterSearchCriteria">
<render fragments="form"/>
</transition>
</action-state>
<view-state id="reviewHotels" redirect="false">
<on-render>
<evaluate expression="bookingService.findHotels(searchCriteria)" result="viewScope.hotels" result-type="dataModel" />
</on-render>

View File

@@ -139,9 +139,9 @@ public interface RequestControlContext extends RequestContext {
public void endActiveFlowSession(String outcome, MutableAttributeMap output) throws IllegalStateException;
/**
* Returns true if the 'always redirect pause' flow execution attribute is set to true, false otherwise.
* Returns true if the 'redirect on pause' flow execution attribute is set to true, false otherwise.
* @return true or false
*/
public boolean getAlwaysRedirectOnPause();
public boolean getRedirectOnPause();
}

View File

@@ -167,16 +167,28 @@ public class ViewState extends TransitionableState {
}
protected void doEnter(RequestControlContext context) throws FlowExecutionException {
context.assignFlowExecutionKey();
if (context.getExternalContext().isResponseAllowed()) {
if (shouldRedirect(context)) {
context.getExternalContext().requestFlowExecutionRedirect();
if (popup) {
context.getExternalContext().requestRedirectInPopup();
ViewState originatingViewState = (ViewState) context.getRequestScope().get("webflow.originatingViewState");
if (this == originatingViewState) {
if (context.getExternalContext().isResponseAllowed()) {
if (context.getExternalContext().isAjaxRequest()) {
View view = viewFactory.getView(context);
render(context, view);
} else {
context.getExternalContext().requestFlowExecutionRedirect();
}
}
} else {
context.assignFlowExecutionKey();
if (context.getExternalContext().isResponseAllowed()) {
if (shouldRedirect(context)) {
context.getExternalContext().requestFlowExecutionRedirect();
if (popup) {
context.getExternalContext().requestRedirectInPopup();
}
} else {
View view = viewFactory.getView(context);
render(context, view);
}
} else {
View view = viewFactory.getView(context);
render(context, view);
}
}
}
@@ -190,9 +202,14 @@ public class ViewState extends TransitionableState {
if (logger.isDebugEnabled()) {
logger.debug("Event '" + event.getId() + "' returned from view " + view);
}
context.getRequestScope().put("webflow.originatingViewState", this);
boolean stateExited = context.handleEvent(event);
if (!stateExited && context.getExternalContext().isResponseAllowed()) {
render(context, view);
if (context.getExternalContext().isAjaxRequest()) {
render(context, view);
} else {
context.getExternalContext().requestFlowExecutionRedirect();
}
}
} else {
if (context.getExternalContext().isResponseAllowed()) {
@@ -224,7 +241,7 @@ public class ViewState extends TransitionableState {
if (redirect != null) {
return redirect.booleanValue();
} else {
return context.getAlwaysRedirectOnPause();
return context.getRedirectOnPause();
}
}

View File

@@ -225,7 +225,7 @@ class RequestControlContextImpl implements RequestControlContext {
flowExecution.endActiveFlowSession(outcome, output, this);
}
public boolean getAlwaysRedirectOnPause() {
public boolean getRedirectOnPause() {
Boolean redirectOnPause = flowExecution.getAttributes().getBoolean("alwaysRedirectOnPause");
return redirectOnPause != null ? redirectOnPause.booleanValue() : false;
}

View File

@@ -500,7 +500,7 @@ The default convention is to treat the id of this view state as the view identif
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Requests this view-state send a flow execution redirect before rendering. Default is false.
Requests this view-state send a flow execution redirect before rendering. Default is false.
]]>
</xsd:documentation>
</xsd:annotation>

View File

@@ -121,7 +121,7 @@ public class MockRequestControlContext extends MockRequestContext implements Req
}
}
public boolean getAlwaysRedirectOnPause() {
public boolean getRedirectOnPause() {
return alwaysRedirectOnPause;
}

View File

@@ -82,7 +82,6 @@ public class SearchFlowExecutionTests extends AbstractXmlFlowExecutionTests {
context.putRequestParameter("id", "1");
resumeFlow(context);
assertCurrentStateEquals("displayResults");
assertResponseWrittenEquals("searchResults", context);
}
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {