6. 必备的语言元素
有四个基本的流程元素:
6.1. flow元素
每个流程都以以下根元素开始:
<?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>
流的所有状态都在此元素内定义。 定义的第一个状态成为流的起点。
6.2. view-state元素
view-state 元素定义了流程中渲染视图的步骤:
<view-state id="enterBookingDetails" />
按照惯例,视图状态会将其 id 映射到流程所在目录中的视图模板。 例如,如果流程本身位于 /WEB-INF/hotels/booking 目录中,前面的状态可能会渲染 /WEB-INF/hotels/booking/enterBookingDetails.xhtml。
6.3. transition元素
transition 元素处理在状态内发生的事件:
<view-state id="enterBookingDetails">
<transition on="submit" to="reviewBooking" />
</view-state>
这些转换驱动视图导航。
6.5. 检查点:基本语言元素
使用 view-state、transition 和 end-state 这三个元素,您可以快速表达您的视图导航逻辑。 团队通常会在添加流行为之前执行此操作,以便他们可以首先专注于与最终用户一起开发应用程序的用户界面。 以下示例流通过使用这些元素实现了其视图导航逻辑:
<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>