Announcement Announcement Module
Collapse
No announcement yet.
Custom Scope for Flash Scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Scope for Flash Scope

    In normal case, we are using post-redirect pattern to submit a form and then redirect to successful page, which is submitting form to controller A and redirect to controller B if success.

    In Stripes, it uses flash scope object to carry result from controller A to another controller B. And Spring Web Flow has similar scope object.

    Just wonder whether there is already an implementation in Spring to provide such a function of flash scope for post-redirect pattern.


    Thanks.

    --Michael

  • #2
    Hi mwang2008,

    Did you ever find out if there is explicit support for the flash scope for the post-redirect pattern?

    Comment


    • #3
      There is not flash scope in Spring MVC.
      I created my own flash scope bean which acts the similar function of Stripes.

      We used it for error case, which when error happends, we redirect to differenct controller (normally, its own controller) with error message.

      For success case, we still use session. This way, user can refersh their page without any problem.

      Comment


      • #4
        Thanks for the swift reply. I was thinking of using it primarily for passing success/failure messages to the controller being redirected to (currently we are just encoding the message in the URL, I'm sure there must be a better way).

        Does you solution handle concurrency?
        For example, a user submits a request to controller A, which adds a message to the flash scope then redirects to controller B to show the message (which does some processing and takes some time to load). In the meantime the user performs another action on another tab which renders a view for controller C, unfortunately this displays the message created by controller A for controller B.

        Looking at the rails version of flash scope they don't mention any handling of this case. http://api.rubyonrails.com/classes/A...ler/Flash.html

        Comment


        • #5
          here's the solution a friend and i came up with. http://mono.syncopated.net/deno/2007...or-spring-mvc/

          Comment


          • #6
            Url no longer available

            Hi, the Url you gave is not responding. Is whatever is there available elsewhere?

            Comment


            • #7
              i moved that blog it's now at http://blog.vichasconsulting.com/archives/12

              Comment


              • #8
                You can use Spring custom scope to achieve this.
                For example:
                <!-- ========= FLASH SCOPE ====================== -->
                <bean class="org.springframework.beans.factory.config.Cu stomScopeConfigurer">
                <property name="scopes">
                <map>
                <entry key="flash">
                <bean class="com.xyz.myapp.scopeManager.flash.FlashScope "/>
                </entry>
                </map>
                </property>
                </bean>

                <bean name="flashManager" class="com.xyz.myapp.scopeManager.flash.FlashManag er" scope="flash">
                <aop:scoped-proxy/>
                <property name="ttl"><value>5</value></property>

                </bean>

                It creates flashManager with flash scope. Controller responses to put content into flashManager. Once particular content is used, it will be remove from flashManager, otherwise the content will live for 5 minutes [defined in config above]

                If anyone interesting, I can give more detail of it.

                Comment


                • #9
                  Hi mwang2008, I would be interested in seeing more details about how you implemented the flash scope manager. Thanks!

                  Comment


                  • #10
                    Flash scope in Spring MVC

                    I implemented a simple solution to this.

                    There's an explanation and code here:

                    http://blog.smartkey.co.uk/2011/01/i...-applications/

                    Comment

                    Working...
                    X