From 16aee2d58798dcabe216e7ca51ff6a764089bd8b Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 28 Apr 2008 21:31:11 +0000 Subject: [PATCH] doc polish --- spring-webflow-reference/src/el.xml | 9 ++ spring-webflow-reference/src/spring-js.xml | 153 +++++++----------- spring-webflow-reference/src/spring-mvc.xml | 4 +- .../src/upgrade-guide.xml | 2 +- spring-webflow-reference/src/views.xml | 8 +- .../mvc/servlet/FlowHandlerAdapter.java | 17 +- 6 files changed, 85 insertions(+), 108 deletions(-) diff --git a/spring-webflow-reference/src/el.xml b/spring-webflow-reference/src/el.xml index 29a3e79e..128b453e 100644 --- a/spring-webflow-reference/src/el.xml +++ b/spring-webflow-reference/src/el.xml @@ -197,6 +197,15 @@ ]]> + + resourceBundle + + Use resourceBundle to access a message resource. + + ]]> + + flowRequestContext diff --git a/spring-webflow-reference/src/spring-js.xml b/spring-webflow-reference/src/spring-js.xml index 84932686..f8ae4064 100644 --- a/spring-webflow-reference/src/spring-js.xml +++ b/spring-webflow-reference/src/spring-js.xml @@ -4,29 +4,24 @@ Introduction - Spring Javascript is intended to be a lightweight wrapper around common JavaScript toolkits such as Dojo. It - aims to provide a common client-side programming model for progressively enhancing a web page with rich - widget behavior and Ajax remoting. + Spring Javascript (spring-js) is a lightweight abstraction over common JavaScript toolkits such as Dojo. + It aims to provide a common client-side programming model for progressively enhancing a web page with rich widget behavior and Ajax remoting. - The Spring Javascript library has been used to apply rich functionality to the Spring MVC + Spring Web Flow - version of the Spring Travel application. + Use of the Spring JS API is demonstrated in the the Spring MVC + Web Flow version of the Spring Travel reference application. + In addition, the JSF components provided as part of the Spring Faces library build in Spring.js. Including Spring Javascript in a Page - Spring Javascript is designed such that an implementation of its API can be built for any of the popular - Javascript toolkits. The first implementation provided is for the Dojo toolkit. (Implementations for jQuery, - Ext, Prototype and YUI will be considered in future releases.) Using Spring Javascript in a page requires - including both the underlying library as normal, the - Spring.js - base interface file and the - Spring-(library implementation).js - file for the corresponding toolkit, in this case - Spring-Dojo.js - . The following scripts includes are used to serve the files from the - ResourceServlet + Spring Javascript is designed such that an implementation of its API can be built for any of the popular Javascript toolkits. + The initial implementation provided is for the Dojo toolkit. + + + Using Spring Javascript in a page requires including the underlying toolkit as normal, + the Spring.js base interface file, and the Spring-(library implementation).js file for the underlying toolkit. + As an example, the following script includes obtain the Dojo implementation of Spring.js: "> @@ -34,10 +29,8 @@ ]]> - When using the widget system from an underlying library, typically you must also include some CSS resources - to obtain the desired look and feel. For the Dojo-based sample, Dojo's - tundra.css - is included: + When using the widget system of an underlying library, typically you must also include some CSS resources to obtain the desired look and feel. + For the Dojo-based reference application, Dojo's tundra.css is included: " />]]> @@ -46,105 +39,84 @@ Spring Javascript Decorations - A central concept in Spring Javascript is the notion of applying decorations to existing DOM nodes. This - technique is used to progressively enhance a web page such that the page will still be functional in a less - capable browser. The - addDecoration - method is used to apply decorations. For example, to enhance a Spring MVC - <form:input> - tag with rich suggestion behavior: + A central concept in Spring Javascript is the notion of applying decorations to existing DOM nodes. + This technique is used to progressively enhance a web page such that the page will still be functional in a less capable browser. + The addDecoration method is used to apply decorations. + + + The following example illustrates enhancing a Spring MVC <form:input> tag with rich suggestion behavior: ]]> - The - ElementDecoration - is used to apply rich widget behavior to an existing DOM node. This decoration type does not aim to - completely hide the underlying toolkit, so the toolkit's native widget type and widget attributes are used - directly. This approach will allow you to use this common decoration model to apply any rich widget from the - underlying toolkit in a consistent manner. + The ElementDecoration is used to apply rich widget behavior to an existing DOM node. + This decoration type does not aim to completely hide the underlying toolkit, so the toolkit's native widget type and attributes are used directly. + This approach allows you to use a common decoration model to integrate any widget from the underlying toolkit in a consistent manner. + See the booking-mvc reference application for more examples of applying decorations to do things from suggestions to client-side validation. - When using the - ElementDecoration - to apply widgets that have rich validation behavior, a common need is to prevent the form from being - submitted to the server until validation passes. This can be done with the - ValidateAllDecoration - : + When using the ElementDecoration to apply widgets that have rich validation behavior, a common need is to prevent the form from being submitted to the server until validation passes. + This can be done with the ValidateAllDecoration: ]]> - This decorates the "Proceed" button with a special onclick event handler that fires the client side - validators and does not allow the form to submit until they pass successfully. + This decorates the "Proceed" button with a special onclick event handler that fires the client side validators and does not allow the form to submit until they pass successfully. - An - AjaxEventDecoration - will apply a client-side event listener that fires a remote Ajax request to the server and installs a - callback for automatically handling the response: + An AjaxEventDecoration applies a client-side event listener that fires a remote Ajax request to the server. It also auto-registers a callback function to link in the response: Previous Results +Previous Results ]]> - This decorates the onclick event of the "Previous Results" link with an Ajax call, passing along a special - parameter that specifies the fragment to be re-rendered in the response. Note that this link would still be - fully functional if Javascript was unavailable in the client. (See the section on - Handling Ajax Requests - for details on how this request is handled on the server.) + This decorates the onclick event of the "Previous Results" link with an Ajax call, passing along a special parameter that specifies the fragment to be re-rendered in the response. + Note that this link would still be fully functional if Javascript was unavailable in the client. + (See the section on Handling Ajax Requests for details on how this request is handled on the server.) - Sometimes it is necessary to calling Spring Javascript's - RemotingHandler - directly instead of using the - AjaxEventDecoration - . For example, see inline - onclick - handler of this button: + Sometimes it is necessary to call Spring Javascript's RemotingHandler directly instead of using the AjaxEventDecoration. + For example, see inline onclick handler of this button: + onclick="Spring.remoting.submitForm('proceed', 'booking', { fragments:'messages,bookingForm' }); return false;" /> ]]> Handling Ajax Requests - Spring Javascript's client-side Ajax response handling is built upon the notion of receiving "fragments" - back from the server. These fragments are just standard HTML that is meant to replace portions of the - existing page. The key piece needed on the server is a way to determine which pieces of a full repsonse need - to be pulled out for partial rendering. + Spring Javascript's client-side Ajax response handling is built upon the notion of receiving "fragments" back from the server. + These fragments are just standard HTML that is meant to replace portions of the existing page. + The key piece needed on the server is a way to determine which pieces of a full response need to be pulled out for partial rendering. In order to be able to render partial fragments of a full response, the full response must be built using a templating technology that allows the use of composition for constructing the response, and for the member - parts of the composition to be referenced and rendered individually. Spring Javascript initially provides - some simple Spring MVC extensions that make use of Tiles to achieve this, but the same effect could - theoretically be achieved with any templating system that meets the same criteria, and more such options - will be explored in future releases. + parts of the composition to be referenced and rendered individually. + Spring Javascript provides some simple Spring MVC extensions that make use of Tiles to achieve this. + The same technique could theoretically be used with any templating system supporting composition. Spring Javascript's Ajax remoting functionality is built upon the notion that the core handling code for an @@ -164,40 +136,31 @@ page=${searchCriteria.page - 1}">Previous Results ]]> - This configures the - AjaxUrlBasedViewResolver - which in turn is able to interpret Ajax requests and create a - FlowAjaxTilesView - to handle rendering of the appropriate fragments. Note that - FlowAjaxTilesView - is capable of handling the rendering for both Web Flow and pure Spring MVC requests. The fragments - correspond to individual attributes of a Tiles view definition. For example, take the following Tiles - view definition: + This configures the AjaxUrlBasedViewResolver which in turn interprets Ajax requests and creates FlowAjaxTilesView objects to handle rendering of the appropriate fragments. + Note that FlowAjaxTilesView is capable of handling the rendering for both Web Flow and pure Spring MVC requests. + The fragments correspond to individual attributes of a Tiles view definition. For example, take the following Tiles view definition: + ]]> - An Ajax request could specify the "body", "hotelSearchForm" or "bookingsTable" to be rendered as - fragments in the request. + An Ajax request could specify the "body", "hotelSearchForm" or "bookingsTable" to be rendered as fragments in the request. Handling Ajax Requests with Spring MVC + Spring Web Flow - Spring Web Flow handles the optional rendering of fragments directly in the flow definition language - through use of the - render - element. The benefit of this approach is that the selection of fragments is completely decoupled from - client-side code, such that no special parameters need to be passed with the request the way they - currently must be with the pure Spring MVC controller approach. For example, if you wanted to render - the "hotelSearchForm" fragment from the previous example Tiles view into a rich Javascript popup: + Spring Web Flow handles the optional rendering of fragments directly in the flow definition language through use of the render element. + The benefit of this approach is that the selection of fragments is completely decoupled from client-side code, such that no special parameters need to be passed with the request the way they + currently must be with the pure Spring MVC controller approach. + For example, if you wanted to render the "hotelSearchForm" fragment from the previous example Tiles view into a rich Javascript popup: diff --git a/spring-webflow-reference/src/spring-mvc.xml b/spring-webflow-reference/src/spring-mvc.xml index ad88e3ad..75e31480 100644 --- a/spring-webflow-reference/src/spring-mvc.xml +++ b/spring-webflow-reference/src/spring-mvc.xml @@ -176,7 +176,7 @@ public class BookingFlowHandler extends AbstractFlowHandler { - + ]]> @@ -198,7 +198,7 @@ public class BookingFlowHandler extends AbstractFlowHandler { - + ]]> diff --git a/spring-webflow-reference/src/upgrade-guide.xml b/spring-webflow-reference/src/upgrade-guide.xml index 4c03bd1e..20eb9749 100644 --- a/spring-webflow-reference/src/upgrade-guide.xml +++ b/spring-webflow-reference/src/upgrade-guide.xml @@ -129,7 +129,7 @@ java org.springframework.webflow.upgrade.WebFlowUpgrader flow-to-upgrade.xml This element replaces previous FlowExecutorFactoryBean bean definitions. + ]]> diff --git a/spring-webflow-reference/src/views.xml b/spring-webflow-reference/src/views.xml index df9c692e..942f1236 100644 --- a/spring-webflow-reference/src/views.xml +++ b/spring-webflow-reference/src/views.xml @@ -216,7 +216,7 @@ public void validateEnterBookingDetails(MessageContext context) { The second way is to define a separate object, called a Validator, which validates your model object. To do this, create a class that defines a public method with the name validate${state}, where state is the id of your view-state. - The method must declare a Object parameter to accept your model object, and a MessageContext parameter for recording validation error messages. + The method must declare a parameter to accept your model object, and a MessageContext parameter for recording validation error messages. For example: + + From within a view or a flow, you may also access message resources using the resourceBundle EL variable: + + ]]> + diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java index 653a3fd8..8382c36e 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java @@ -19,18 +19,11 @@ import java.io.IOException; import java.util.Iterator; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.js.ajax.AjaxHandler; import org.springframework.js.ajax.SpringJavascriptAjaxHandler; -import org.springframework.util.Assert; -import org.springframework.web.servlet.HandlerAdapter; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.support.WebContentGenerator; import org.springframework.webflow.context.servlet.DefaultFlowUrlHandler; import org.springframework.webflow.context.servlet.FlowUrlHandler; import org.springframework.webflow.context.servlet.ServletExternalContext; @@ -42,6 +35,8 @@ import org.springframework.webflow.execution.repository.NoSuchFlowExecutionExcep import org.springframework.webflow.executor.FlowExecutionResult; import org.springframework.webflow.executor.FlowExecutor; +import com.sun.tools.javac.tree.Tree$Assert; + /** * A custom MVC HandlerAdapter that encapsulates the generic workflow associated with executing flows in a Servlet * environment. Delegates to mapped {@link FlowHandler flow handlers} to manage the interaction with executions of @@ -365,8 +360,12 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd sendRedirect(url.toString(), response); } - private void sendRedirect(String url, HttpServletResponse response) throws IOException { - response.sendRedirect(response.encodeRedirectURL(url)); + private void sendRedirect(String url, HttpServletRequest request, HttpServletResponse response) throws IOException { + if (ajaxHandler.isAjaxRequest(getServletContext(), request, response)) { + ajaxHandler.sendAjaxRedirect(getServletContext(), request, response, url, false); + } else { + response.sendRedirect(response.encodeRedirectURL(url)); + } } private void handleFlowException(FlowException e, HttpServletRequest request, HttpServletResponse response,