docs
This commit is contained in:
@@ -143,19 +143,22 @@
|
||||
<title>Binding to a model</title>
|
||||
<para>
|
||||
Use the <code>model</code> attribute to declare a model object the view binds to.
|
||||
This attribute is typically used with views that render data controls, such as forms.
|
||||
This attribute is typically used in conjunction with views that render data controls, such as forms.
|
||||
It enables form data binding and validation behaviors to be driven from metadata on your model object.
|
||||
</para>
|
||||
<para>
|
||||
The following example declares an <code>enterBookingDetails</code> state manipulates the <code>booking</code> model:
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="enterBookingDetails" model="booking">]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The model may be in any accessible scope, such as <code>flowScope</code> or <code>viewScope</code>.
|
||||
The model may an object in any accessible scope, such as <code>flowScope</code> or <code>viewScope</code>.
|
||||
Specifying a <code>model</code> triggers the following behavior when a view event occurs:
|
||||
</para>
|
||||
<orderedlist>
|
||||
<listitem><para>View-to-model binding. On view postback, form values are bound to model object properties for you.</para></listitem>
|
||||
<listitem><para>Model validation. After binding, if the model object requires validation, that validation logic will be invoked.</para></listitem>
|
||||
<listitem><para>View-to-model binding. On view postback, user input values are bound to model object properties for you.</para></listitem>
|
||||
<listitem><para>Model validation. After binding, if the model object requires validation that validation logic will be invoked.</para></listitem>
|
||||
</orderedlist>
|
||||
<para>
|
||||
For a flow event to be generated that can drive a view state transition, model binding must complete successfully.
|
||||
@@ -166,6 +169,7 @@
|
||||
<title>Suppressing binding</title>
|
||||
<para>
|
||||
Use the <code>bind</code> attribute to suppress model binding and validation for particular view events.
|
||||
The following example suppresses binding when the <code>cancel</code> event occurs:
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="enterBookingDetails" model="booking">
|
||||
@@ -174,6 +178,76 @@
|
||||
</view-state>]]>
|
||||
</programlisting>
|
||||
</sect1>
|
||||
<sect1 id="view-binder">
|
||||
<title>Specifying bindings explicitly</title>
|
||||
<para>
|
||||
Use the <code>binder</code> element to configure the exact set of model bindings usable by the view.
|
||||
This is particularly useful in a Spring MVC environment for restricting the set of "allowed fields" per view.
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="enterBookingDetails" model="booking">
|
||||
<binder>
|
||||
<binding property="creditCard" />
|
||||
<binding property="creditCardName" />
|
||||
<binding property="creditCardExpiryMonth" />
|
||||
<binding property="creditCardExpiryYear" />
|
||||
</binder>
|
||||
<transition on="proceed" to="reviewBooking" />
|
||||
<transition on="cancel" to="cancel" bind="false" />
|
||||
</view-state>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
If the binder element is not specified, all public properties of the model are eligible for binding by the view.
|
||||
With the binder element specified, only the explicitly configured bindings are allowed.
|
||||
</para>
|
||||
<para>
|
||||
Each binding may also apply a converter to format the model property value for display in a custom manner.
|
||||
If no converter is specified, the default converter for the model property's type will be used.
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="enterBookingDetails" model="booking">
|
||||
<binder>
|
||||
<binding property="checkinDate" converter="shortDate" />
|
||||
<binding property="checkoutDate" converter="shortDate" />
|
||||
<binding property="creditCard" />
|
||||
<binding property="creditCardName" />
|
||||
<binding property="creditCardExpiryMonth" />
|
||||
<binding property="creditCardExpiryYear" />
|
||||
</binder>
|
||||
<transition on="proceed" to="reviewBooking" />
|
||||
<transition on="cancel" to="cancel" bind="false" />
|
||||
</view-state>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
In the example above, the <code>shortDate</code> converter is bound to the
|
||||
<code>checkinDate</code> and <code>checkoutDate</code> properties.
|
||||
Custom converters may be registered with the application's ConversionService.
|
||||
</para>
|
||||
<para>
|
||||
Each binding may also apply a required check that will generate a validation error
|
||||
if the user provided value is null on form postback:
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="enterBookingDetails" model="booking">
|
||||
<binder>
|
||||
<binding property="checkinDate" converter="shortDate" required="true" />
|
||||
<binding property="checkoutDate" converter="shortDate" required="true" />
|
||||
<binding property="creditCard" required="true" />
|
||||
<binding property="creditCardName" required="true" />
|
||||
<binding property="creditCardExpiryMonth" required="true" />
|
||||
<binding property="creditCardExpiryYear" required="true" />
|
||||
</binder>
|
||||
<transition on="proceed" to="reviewBooking">
|
||||
<transition on="cancel" to="bookingCancelled" bind="false" />
|
||||
</view-state>]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
In the example above, all of the bindings are required.
|
||||
If one or more blank input values are bound, validation errors will be generated and the view will re-render with those errors.
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="view-validate">
|
||||
<title>Validating a model</title>
|
||||
<para>
|
||||
@@ -238,7 +312,30 @@ public class BookingValidator {
|
||||
</para>
|
||||
</sect3>
|
||||
</sect2>
|
||||
<sect2 id="view-validation-declarative">
|
||||
<title>Declarative validation</title>
|
||||
<para>
|
||||
Spring Web Flow does not yet ship integration with a declarative validation framework such as Hibernate Validator.
|
||||
It is expected that integration will be provided in a future Web Flow release.
|
||||
This integration will allow declarative validation constraints to be defined against model properties.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
<sect1 id="view-validation-suppression">
|
||||
<title>Suppressing validation</title>
|
||||
<para>
|
||||
Use the <code>validate</code> attribute to suppress model validation for particular view events:
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<view-state id="chooseAmenities" model="booking">
|
||||
<transition on="proceed" to="reviewBooking">
|
||||
<transition on="back" to="enterBookingDetails" validate="false" />
|
||||
</view-state>]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
In this example, data binding will still occur on <code>back</code> but validation will be suppressed.
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="transition-actions">
|
||||
<title>Transition actions</title>
|
||||
<para>
|
||||
|
||||
Reference in New Issue
Block a user