6. 基本语言元素

有四个基本的流元件:spring-doc.cadn.net.cn

6.1. 使用flow元素

每个流都以以下根元素开头:spring-doc.cadn.net.cn

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          https://www.springframework.org/schema/webflow/spring-webflow.xsd">

</flow>

流的所有状态都在此元素中定义。 定义的第一个状态将成为流的起点。spring-doc.cadn.net.cn

6.2. 使用view-state元素

view-state元素定义呈现视图的流的一个步骤:spring-doc.cadn.net.cn

<view-state id="enterBookingDetails" />

按照惯例,视图状态会将其 ID 映射到流所在目录中的视图模板。 例如,前面的 state 可能会呈现/WEB-INF/hotels/booking/enterBookingDetails.xhtml如果流本身位于/WEB-INF/hotels/booking目录。spring-doc.cadn.net.cn

6.3. 使用transition元素

transition元素处理状态中发生的事件:spring-doc.cadn.net.cn

<view-state id="enterBookingDetails">
    <transition on="submit" to="reviewBooking" />
</view-state>

这些过渡驱动视图导航。spring-doc.cadn.net.cn

6.4. 使用end-state元素

end-state元素定义流结果:spring-doc.cadn.net.cn

<end-state id="bookingCancelled" />

当流转换为最终状态时,它将结束并返回结果。spring-doc.cadn.net.cn

6.5. 检查点:基本语言元素

有了这三个元素,view-state,transitionend-state,您可以快速表达您的视图导航逻辑。 团队通常在添加流行为之前执行此作,以便他们可以首先专注于与最终用户一起开发应用程序的用户界面。 以下示例流使用以下元素实现其视图导航逻辑:spring-doc.cadn.net.cn

<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          https://www.springframework.org/schema/webflow/spring-webflow.xsd">

    <view-state id="enterBookingDetails">
        <transition on="submit" to="reviewBooking" />
    </view-state>

    <view-state id="reviewBooking">
        <transition on="confirm" to="bookingConfirmed" />
        <transition on="revise" to="enterBookingDetails" />
        <transition on="cancel" to="bookingCancelled" />
    </view-state>

    <end-state id="bookingConfirmed" />

    <end-state id="bookingCancelled" />

</flow>