<?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-1.0.xsd">

  <start-state idref="captcha"/>

  <subflow-state id="captcha" flow="captcha-sub-flow">
    <transition on="finish" to="init"/>
  </subflow-state>

  <action-state id="init">
    <action bean="registrationAction" method="init"/>
    <transition on="success" to="userForm"/>
  </action-state>

  <subflow-state flow="user/form-sub-flow" id="userForm">
    <attribute-mapper>
      <input-mapper>
        <input-attribute name="pageTitleCode" required="true"/>
        <input-attribute name="formSubmitCode" required="true"/>
      </input-mapper>
      <output-mapper>
        <output-attribute name="user" required="true"/>
      </output-mapper>
    </attribute-mapper>
    <transition on="finish" to="mailAddrForm"/>
  </subflow-state>

  <view-state id="mailAddrForm" view="account.MailAddrRegisterForm">
    <render-actions>
      <action bean="account.mailAddrRegisterAction" method="setupForm"/>
    </render-actions>
    <transition on="submit" to="register">
      <action bean="account.mailAddrRegisterAction" method="bindAndValidate"/>
    </transition>
  </view-state>

  <action-state id="register">
    <action bean="registrationAction" method="register"/>
    <transition on="success" to="mailSendOrNot"/>
    <transition on-exception="org.unitedfront2.domain.UserCodeUsedByOtherException" to="userForm"/>
    <transition on-exception="org.unitedfront2.domain.UserNameUsedByOtherException" to="userForm"/>
  </action-state>

  <decision-state id="mailSendOrNot">
    <if test="${flowScope.sendMail}" then="mailSendFinish" else="mailNotSendFinish"/>
  </decision-state>

  <end-state id="mailSendFinish" view="RegistrationSuccess"/>

  <end-state id="mailNotSendFinish" view="RegistrationSuccessNotSendMail"/>

</flow>
