Announcement Announcement Module
Collapse
No announcement yet.
Question with regards to JSP beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question with regards to JSP beans

    Hi,

    There may be something I'm missing, how do you access wired webflow beans from a jsp page? I tried <jsp:useBean ..> thinking that all my beans were singletons and useBean if it can find an existing bean with the same id and scope will use it, but it seems I'm not getting the correct beans.

    Jsp:
    <%@page import=".. bl.Cache ..">
    <jsp:useBean id="blCache" class="bl.Cache" />
    <% String id=blCache.getId() %>

    app-flow-beans.xml:
    <bean id="blCache" class="bl.Cache">
    <property name="logger"><ref bean="logger"/>
    </bean>

    java:
    public class Cache {
    protected ILogger logger;
    protected String id;
    public String getId() { return id; }
    public void setLogger(...)
    }

    Thanks

  • #2
    This works:

    In the pre-action (bl-flow.xml):
    <action-state id="doCache">
    <action bean="actionCache"/>
    <transition on="eventStart" to="showWelcome"/>

    Comment


    • #3
      Sorry disregard the previous incomplete message. What I wanted to say was:

      This works:

      In the pre-action (bl-flow.xml):
      <action-state id="doCache">
      <action bean="actionCache"/>
      <transition on="eventStart" to="showWelcome"/>
      ...

      in the ActionCache.java:
      ServletExternalContext externalContext = (ServletExternalContext)context.getExternalContext ();
      HttpServletRequest request = externalContext.getRequest();
      HttpSession session = request.getSession();
      session.setAttribute("blCache", blCache);

      and in the jsp page:
      <%
      bl.Cache blCache =(bl.Cache) request.getSession().getAttribute("blCache");
      %>

      Is that the correct way to do it? Isn't there a simpler way to get to this bean?

      Thanks.

      Comment


      • #4
        I still would like to solicit your opinions on this solution. Is it the right way to go?

        Thanks.

        Comment


        • #5
          The "bean" referenced by an action resides in a Spring application context and is not directly available to a JSP.

          SWF will merge the contents of all its scopes (request, flash, flow, conversation) together and expose that data to the JSP through request attributes. So if you have something like "foo" in your flow scope (or any other scope), you can do in your JSP:

          ${foo}

          <%=request.getAttribute("foo") %>

          <jsp:useBean id="foo" class="..."/>

          Normally you don't want/need to access the 'service' beans difened in your application context from your JSP, so ASAIK there is not easy way to do that.

          Erwin

          Comment

          Working...
          X