<?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
      http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

  <secured attributes="ROLE_USER, ROLE_ADMIN"/>

  <var name="emailForwardingSettings" class="org.unitedfront2.web.controller.EmailForwardingSettings"/>

  <on-start>
    <set name="requestScope.user" value="externalContext.requestMap._user."/>
    <evaluate expression="emailForwardingTable.find(user.id)" result="emailForwardingSettings.settings"/>
  </on-start>

  <view-state id="form" view="EmailForwarding" model="emailForwardingSettings">
    <transition on="submit" to="update">
      <evaluate expression="emailForwardingAction.bind"/>
    </transition>
  </view-state>

  <action-state id="update">
    <set name="requestScope.user" value="externalContext.requestMap._user."/>
    <evaluate expression="emailForwardingTable.update(user.id, emailForwardingSettings.settings)"/>
    <transition on="success" to="form"/>
  </action-state>

</flow>
