Announcement Announcement Module
No announcement yet.
Custom Scope for Flash Scope Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.



  • #2
    Hi mwang2008,

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


    • #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.


      • #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.


        • #5
          here's the solution a friend and i came up with.


          • #6
            Url no longer available

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


            • #7
              i moved that blog it's now at


              • #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">
                <entry key="flash">
                <bean class=" "/>

                <bean name="flashManager" class=" er" scope="flash">
                <property name="ttl"><value>5</value></property>


                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.


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


                  • #10
                    Flash scope in Spring MVC

                    I implemented a simple solution to this.

                    There's an explanation and code here: