From 358f30598e375f4e5351b987743e3cd0b2ee2cf9 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 10 Apr 2008 02:26:00 +0000 Subject: [PATCH] --- spring-webflow-reference/src/system-setup.xml | 10 +++ spring-webflow-reference/src/views.xml | 77 +++++++++++++++---- 2 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 spring-webflow-reference/src/system-setup.xml diff --git a/spring-webflow-reference/src/system-setup.xml b/spring-webflow-reference/src/system-setup.xml new file mode 100644 index 00000000..ca9de59b --- /dev/null +++ b/spring-webflow-reference/src/system-setup.xml @@ -0,0 +1,10 @@ + + + System Setup + + Introduction + + This chapter shows you how to setup the Web Flow system for use in any web environment. + + + \ No newline at end of file diff --git a/spring-webflow-reference/src/views.xml b/spring-webflow-reference/src/views.xml index 559a675a..41176ade 100644 --- a/spring-webflow-reference/src/views.xml +++ b/spring-webflow-reference/src/views.xml @@ -82,7 +82,7 @@ A view-state destroys its viewScope when it exits. - Assigning a viewScope variable using an Action + Assigning a viewScope variable using an action Variables are often assigned before the view renders: @@ -93,7 +93,7 @@ - Using the var tag to allocate view variables + Using the var element to allocate view variables Use the var tag to declare a view variable. Like a flow variable, any @Autowired references are automatically restored when the view state resumes. @@ -130,7 +130,7 @@ on-render - Use the on-render element to execute one or more actions before view rendering + Use the on-render element to execute one or more actions before view rendering. Render actions are executed on the initial render as well as any subsequent refreshes, including any partial re-renderings of the view. @@ -143,6 +143,7 @@ Model binding Use the model attribute to declare a model object the view binds to. + This attribute is typically used with views that render data controls, such as forms. The following example declares the enterBookingDetails state manipulates the booking model: @@ -163,7 +164,7 @@ The exact model binding and validation semantics are a function of the view technology in use. See the Spring MVC and Faces section for more information on MVC and JSF semantics, respectively. - Regardless of the view technology used, the flow definition metadata should not change. + Regardless of the view technology used, your flow should not change. @@ -192,7 +193,7 @@ Implementing a model validate method - The first way has you define a validate method on the model object class. + The first way is to define a validate method on the model object class. To do this, create a public method with the name validate<state>, where state is the id of the view-state. The method must declare a MessageContext parameter for recording validation error messages. For example: @@ -200,8 +201,7 @@ public void validateEnterBookingDetails(MessageContext context) { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -1); - if (checkinDate.before(calendar.getTime())) { + if (checkinDate.before(today())) { context.addMessage(new MessageBuilder().error().source("checkinDate").defaultText( "Check in date must be a future date").build()); } else if (!checkinDate.before(checkoutDate)) { @@ -214,7 +214,7 @@ public void validateEnterBookingDetails(MessageContext context) { Implementing a Validator - The second way has you define a separate object, called a Validator, which validates your model object. + 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 the view-state. The method must declare a Object parameter to accept your model object, and a MessageContext parameter for recording validation error messages. For example: @@ -223,9 +223,7 @@ public void validateEnterBookingDetails(MessageContext context) { public class BookingValidator { public void validateEnterBookingDetails(Object object, MessageContext context) { Booking booking = (Booking) object; - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -1); - if (booking.getCheckinDate().before(calendar.getTime())) { + if (booking.getCheckinDate().before(today())) { context.addMessage(new MessageBuilder().error().source("checkinDate").defaultText( "Check in date must be a future date").build()); } else if (!booking.getCheckinDate().before(checkoutDate)) { @@ -236,7 +234,7 @@ public class BookingValidator { } - A Validator can also accept a Spring MVC Errors object, useful for invoking existing Spring Validators. + A Validator can also accept a Spring MVC Errors object, which is required for invoking existing Spring Validators. @@ -256,7 +254,7 @@ public class BookingValidator { They simply execute their actions and re-render the current view or one or more fragments of the current view. - render + Partial re-rendering Use the render element to request partial re-rendering of a view after handling an event: @@ -266,12 +264,63 @@ public class BookingValidator { <render fragments="searchResultsFragment" /> </transition> + + The fragments attribute should reference the ID(s) of the view element(s) you wish to re-render. + Specify multiple elements to re-render by separating them with a comma delimiter. + + + Such partial rendering is often used with events signaled by Ajax to update a specific zone of the view. + + + + + Messages + + Spring Web Flow's MessageContext is an API for recording messages during the course of flow executions. + Plain text messages can be added to the context, as well as internationalized messages resolved by a Spring MessageSource. + Messages are renderable by views and automatically survive flow execution redirects. + Three distinct message severities are provided: info, warning, and error. + In addition, a convenient MessageBuilder exists for fluently constructing messages. + + + Adding plain text messages + +MessageContext context = ... +MessageBuilder builder = new MessageBuilder(); +context.addMessage(builder.error().source("checkinDate").defaultText("Check in date must be a future date").build()); +context.addMessage(builder.warn().source("smoking").defaultText("Smoking is bad for your health").build()); +context.addMessage(builder.info().defaultText("We have processed your reservation - thank you and enjoy your stay").build()); + + + + Adding internationalized messages + +MessageContext context = ... +MessageBuilder builder = new MessageBuilder(); +context.addMessage(builder.error().source("checkinDate").code("checkinDate.notFuture").build()); +context.addMessage(builder.warn().source("smoking").code("notHealthy").resolvableArg("smoking").build()); +context.addMessage(builder.info().code("reservationConfirmation").build()); + + + + Flow message bundles + + Internationalized messages are defined in message bundles accessed by a Spring MessageSource. + To create a flow-specific message bundle, simply define messages.properties file(s) in your flow's directory. + Create a default messages.properties file and a .properties file for each additional Locale you need to support. + + +#messages.properties +checkinDate=Check in date must be a future date +notHealthy={0} is bad for your health +reservationConfirmation=We have processed your reservation - thank you and enjoy your stay + popup - Use the popup attribute to indicate the view should be rendered in a model popup dialog: + Use the popup attribute to render a view in a modal popup dialog: <view-state id="changeSearchCriteria" view="enterSearchCriteria.xhtml" popup="true">