<?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"/>

  <on-start>
    <set name="requestScope.communityCode" value="requestParameters.communityCode"/>
    <set name="requestScope.threadId" value="requestParameters.threadId" type="int"/>
    <set name="requestScope.user" value="externalContext.requestMap._user"/>
    <set name="flowScope.community" value="communityTable.findByCodeForPost(communityCode, user)"/>
    <set name="flowScope.thread" value="community.findThreadForWrite(threadId, user)"/>
  </on-start>

  <subflow-state id="updateForm" subflow="message.form-sub-flow">
    <input name="pageTitleCode" value="'community.ThreadUpdateForm'"/>
    <input name="formSubmitCode" value="'doUpdate'"/>
    <input name="subjectRequired" value="true"/>
    <input name="message" value="thread.overview"/>
    <output name="message" value="flowScope.overview" required="true"/>
    <transition on="finish" to="update"/>
  </subflow-state>

  <action-state id="update">
    <evaluate expression="domainFactory.prototype(overview).store()"/>
    <transition to="finish"/>
  </action-state>

  <end-state id="finish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/${flowScope.thread.id}/index.html"/>

</flow>
