-
May 8th, 2007, 01:51 PM
#1
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
-
May 8th, 2007, 03:22 PM
#2
This works:
In the pre-action (bl-flow.xml):
<action-state id="doCache">
<action bean="actionCache"/>
<transition on="eventStart" to="showWelcome"/>
-
May 8th, 2007, 03:25 PM
#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.
-
May 10th, 2007, 12:58 PM
#4
I still would like to solicit your opinions on this solution. Is it the right way to go?
Thanks.
-
May 21st, 2007, 04:13 AM
#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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules