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 映射到流所在目录中的视图模板。
例如,前面的 state 可能会呈现/WEB-INF/hotels/booking/enterBookingDetails.xhtml
如果流本身位于/WEB-INF/hotels/booking
目录。
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>