6. 基本语言要素

有四个基本的流程要素:spring-doc.cadn.net.cn

6.1. 该元素

每个流都以以下根元素开始: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. 该视图状态元素

视图状态元素定义了流程中的一个步骤,用于渲染一个视图:spring-doc.cadn.net.cn

<view-state id="enterBookingDetails" />

按照惯例,视图状态会将其 id 映射到流所在目录中的视图模板。 例如,前一个状态可能/网-信息/酒店/预订/enterBookingDetails.xhtml如果流本身位于/WEB-INF/酒店/预订目录。spring-doc.cadn.net.cn

6.3. 该过渡元素

过渡元素处理发生在状态内的事件:spring-doc.cadn.net.cn

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

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

6.4. 该终态元素

终态元素定义了一个流的结果:spring-doc.cadn.net.cn

<end-state id="bookingCancelled" />

当一个流程转变为终点状态时,它结束,结果返回。spring-doc.cadn.net.cn

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

结合三元素,视图状态,过渡终态你可以快速表达你的视图导航逻辑。 团队通常在添加流程行为之前就这样做,以便优先与终端用户共同开发应用的用户界面。 以下示例流程通过以下元素实现其视图导航逻辑: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>