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

  <var name="comment" class="org.unitedfront2.domain.communication.Comment"/>

  <view-state id="view" view="blog.EntryView" model="comment">
    <binder>
      <binding property="text"/>
    </binder>
    <on-entry>
      <set name="requestScope.blogCode" value="requestParameters.blogCode"/>
      <set name="requestScope.entryCode" value="requestParameters.entryCode"/>
      <set name="requestScope.user" value="externalContext.requestMap._user"/>
      <evaluate expression="blogTable.findByCodeForRead(blogCode, user)" result="flashScope.blog,flowScope.blog"/>
      <evaluate expression="blog.canComment(user)" result="flashScope.canComment"/>
      <evaluate expression="blogEntryTable.findByCodeForRead(entryCode, user)" result="flashScope.entry,flowScope.entry"/>
      <evaluate expression="blog.owner.profile.footmark(user)"/>
      <evaluate expression="blogEntryViewAction.setTitleCode"/>
    </on-entry>
    <transition on="submit" to="captcha">
      <evaluate expression="blog.commentAccess(externalContext.requestMap._user)"/>
    </transition>
  </view-state>

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

  <action-state id="post">
    <evaluate expression="blogEntryViewAction.postComment"/>
    <transition on="success" to="finish"/>
  </action-state>

  <end-state id="finish" view="externalRedirect:contextRelative:/blog/${flowScope.blog.code}/entry-${flowScope.entry.code}.html#comment${flowScope.comment.id}"/>

</flow>
