Announcement Announcement Module
Collapse
No announcement yet.
Scopes with Webflow and JSTL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scopes with Webflow and JSTL

    Like most people (I presume) I'm using JSTL EL to access the data setup in my form and action objects from within my JSPs. I'm slightly confused with how the different scopes work in webflow. Nothing's wrong, everything's working in my app, but I just want to understand how it works.

    1) I can access data from my form bean, as follows:

    <c:out value="${myForm.name}"/>

    What scope is this as far as the JSP is concerned?


    2) I can access attributes setup in my action class, as follows:

    context.getFlowScope().put("MyFlowScope", "My Flow Scope!"); // in the action class

    <c:out value="${MyFlowScope}"/> // in the JSP

    So this is Webflow 'flow scope'. So I presume this is only accessible by a page served by webflow. I notice that this attribute is not accessible via the usual request.getParameter() or session.getAttribute() calls.

    Which leads me to:

    3) How do webflow scopes interact with the standard scopes (page, request, session, application)? Are they completely seperate things? Can I access these (request, session etc) from within my webflow action classes? For example, I may want to set a session attribute for use in another part of my application not served by webflow.

    And finally:

    4) How does JSTL know which scope to look for? Say there is a parameter setup in both flow scope, and session or request scope, what is the logic within JSTL that decides which to use?


    Thanks, if you can help!

  • #2
    So this is Webflow 'flow scope'. So I presume this is only accessible by a page served by webflow. I notice that this attribute is not accessible via the usual request.getParameter() or session.getAttribute() calls.
    try request.getAttribute().

    All the properties in all the scopes are merged into the request attributes before the page is about to render. So the page doesn't have a real notion of the different scopes.

    3) How do webflow scopes interact with the standard scopes (page, request, session, application)? Are they completely seperate things? Can I access these (request, session etc) from within my webflow action classes? For example, I may want to set a session attribute for use in another part of my application not served by webflow.
    They are different things. You can store things in the Session by calling the getSessionMap on the ExternalContext (which you can get by calling getExternalContext on the RequestContext).

    4) How does JSTL know which scope to look for? Say there is a parameter setup in both flow scope, and session or request scope, what is the logic within JSTL that decides which to use?
    The properties are merged into 1 map, so properties with the same name in different scopes are overriden by each other.

    Code:
    public AttributeMap getModel() {
      return getConversationScope().union(getFlowScope()).union(getFlashScope()).union(getRequestScope());
    }

    Comment


    • #3
      That's great, thanks Martin, everything's much clearer now.

      One thing, I did some tests on the final point about different scopes having variables of the same name, and the Flash scope seemed to take priority. Is that just luck, or a concious decision?

      Comment


      • #4
        Request scope does take precedence, but you're seeing an alwaysRedirectOnPause side effect. Check this tip for details:
        http://www.ervacon.com/products/swf/tips/tip4.html

        Erwin

        Comment

        Working...
        X