Announcement Announcement Module
Collapse
No announcement yet.
RE: Still facing problems in accessing the beans in scopes other than flow scope. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RE: Still facing problems in accessing the beans in scopes other than flow scope.

    Hi,
    Please refer to my earlier post at
    http://forum.springframework.org/showthread.php?t=38731

    Thanks Keith and Jeremy for your replies.

    I have tried to use the variable resolver in the following way
    FacesContext context = FacesContext.getCurrentInstance();
    MyLoginClass login = (MyLoginClass)context.getApplication().getVariable Resolver().resolveVariable(context, "login");

    However in this way I get the new instance of the MyLoginClass bean. It doesn't provide me the instance with which the form data is bound.

    The point here I want to make is, if I put the same bean in flow scope everything works well, I think the instance of the bean must have been added in the flow scope map as soon as it is created. However in case of Flash scope, the flash map is not updated with the instance and hence I cannot get it when I try to retrieve it either using the request context or using the variable resolver strategy.

    Could there be any other solution to this problem. I have been held up at the same place for a long time.

    I would really appreciate your help.

    Regards,
    Shashi

  • #2
    Probably,

    update flash-scoped bean (JSF) --> clear flash scope (SWF) --> process event (SWF)

    Comment


    • #3
      It sounds like your authentication action is defined outside the scope of the login form's view state. Recall from the webflow documentation the semantics of Flash scope:

      "Cleared when the next user event is signaled into the flow session; eligible for garbage collection when the flow session ends."

      Thus what is probably happening is that your login form view state is signaling the next event, causing Flash scope to be cleared before your authentication action is reached. Another way to think of Flash scope is more like "Page" scope, meaning the items you store there will be available for the life of a given page. This is most useful (beyond its utility in the alwaysRedirectOnPause scenario) for richer views where you have several fine-grained operations that occur within the scope of that page before signaling the next navigation event. In your particular scenario, it sounds like Flow scope is the appropriate choice.

      Though that does bring to light an interesting question for Keith and Erwin. Correct me if I'm wrong, I seem to recall you guys saying that you deliberated for a good while in determining the appropriate semantics for Flash scope. I'm curious if the idea was ever entertained of allowing the items in Flash scope to live until the next view state has actually finished rendering, as opposed to clearing them out as soon as the event is signaled as is done now?

      -Jeremy

      Comment


      • #4
        Yes we've been discussing this recently--that FlashScope should be associated with the FlowExecution and be cleared after event processing not before. This would scope it higher than a FlowSession (e.g. a specific flow within the stack of flows of an execution--if subflows have been spawned). Also, the data would be available during event processing of the user event.

        How do you feel about this?

        Keith

        Comment


        • #5
          Yes we've been discussing this recently--that FlashScope should be associated with the FlowExecution and be cleared after event processing not before. Also, the data would be available during event processing of the user event. http://opensource.atlassian.com/proj...browse/SWF-221 tracks this.

          How do you feel about this?

          Keith

          Comment


          • #6
            be cleared after event processing not before.
            After redirecting, is the flash-scoped bean alive?

            Comment


            • #7
              I like the idea of keeping the items in FlashScope alive a little longer, i.e. for the duration of the external user event processing. This could provide some nice conveniences, but the more I think about it, I wonder if it is not as simple as it initially appears?

              Just as the user in the original thread (
              http://forum.springframework.org/showthread.php?t=32364) that spawned SWF-221, I have cases where I need to access something that was put into FlashScope in the previous view state. Usually in my case it is to conditionally preload certain model objects in an action while transitioning to the next view state. The objects I need to inspect are no longer in FlashScope when the action executes, but that's not really a big deal for my case since I still have a reference to the objects in the previous view's JSF request-scoped backing bean which is still available to me via expressions. The only downside to this is that I have a tight coupling between the action and the previous view state. If I wanted to decouple them completely, I could have some extra code to move the needed objects out of Flash scope and maybe into the FlowRequestScope instead before the event gets signaled, but in my particular case it is just more convenient to access the objects through expressions that reference the previous backing bean. On the other hand, if I could still access those objects through FlashScope instead, I could decouple the action from the previous view and still have the convenience of accessing the needed objects via expressions.

              Getting back to my question, I suppose the answer hinges on when exactly the FlashScope gets cleaned out, and perhaps how it gets cleaned out. What is the exact duration of an external user event? Does it span, for example, the request from a paused view state all the way through the rendering of the next view state? If so, I would think care would need to be taken to make sure you are only cleaning out the old objects from FlashScope, and not removing anything new that was added during the processing of the event. In other words, before event processing starts, take a snapshot of the contents of the FlashScope, then after processing is complete, only cleanup the objects from that initial snapshot. As long as it is managed with this in mind, I am in favor of the idea.

              -Jeremy

              Comment


              • #8
                I think this is SWF+JSF issue.
                Flash scope should be cleared before "Apply Request Values" phase.

                Comment


                • #9
                  before "Apply Request Values" phase.
                  This is uncertain.
                  What I want to say is "Before JSF updates flash-scoped bean. "

                  Comment


                  • #10
                    Hi,

                    Thanks for your replies.

                    You have guessed it right. The authentication action is not in the scope of the Login view state. I have pasted below the snippet from my flow xml.

                    <view-state id="login" view="/Login.jsp">
                    <transition on="submit" to="authenticate">
                    <action bean="Validator" method="validate"/>
                    </transition>
                    </view-state>
                    <action-state id="authenticate">
                    <action bean="Authentication" method="authenticate"/>
                    <transition on="success" to="homePage" />
                    <transition on="error" to="showError" />
                    </action-state>

                    Here, as you see, I have added another action called for validating the login bean data and is in the scope of the view state, however in this action for validation as well, I don't get the login bean instance with the form data.

                    Anyways, what I want to know is, I cannot put my login bean in the flow scope. Since it will be available as long as the flow doesn't end. I don't want it in the flow. I don't want to create a separate flow only for authentication in order to just use the login bean in flow scope.

                    Is there any other scope (like request) where the bean life cycle will be managed by spring and the bean instance won't be available after the authentication action is over. I want to know more about the scope similar to request here.

                    Would appreciate your help.

                    Regards,
                    Shashi

                    Comment


                    • #11
                      Originally posted by shashi View Post
                      Is there any other scope (like request) where the bean life cycle will be managed by spring and the bean instance won't be available after the authentication action is over. I want to know more about the scope similar to request here.
                      In this particular instance then, why not just use request scope? It seems it would fulfill your needs exactly.

                      -Jeremy

                      Comment


                      • #12
                        Hi Jeremy,

                        Thanks for your reply.

                        To use a bean in request scope, I think I don't have to define any scope for the bean, the way mentioned below:

                        <bean id="login" class="MyLoginClass"/>

                        and access the bean in the jsp as

                        <h:inputText id="loginid" value="#{login.id}"/>
                        <h:inputText id="password" value="#{login.password}"/>

                        However I still get the bean as null in the request scope. Is there anything I am doing here?

                        Thanks once more for your help,
                        Shashi

                        Comment


                        • #13
                          You need to explicitly specify request scope. The config you show will use the Spring default of singleton scope, which is definitely not what you want.

                          Keep in mind that http request scope and flow request scope (that accessible through RequestContext) are two different things. When you define your bean as:

                          Code:
                          <bean id="login" class="MyLoginClass" scope="request"/>
                          you are defining it in http request scope. If you are trying to then manipulate it from your intermediary action, the cleanest and easiest thing is to use Spring's dependency injection. On the other hand, if you for some reason defined the bean as a JSF managed bean in request scope, you could use the same code as I described before where you try to access the bean using JSF's variable resolution mechanism.

                          -Jeremy

                          Comment

                          Working...
                          X