0

exception accession spring bean with session scope from composer event handler

asked 2008-11-04 21:55:51 +0800

DaveWild gravatar image DaveWild
18 1

I'm having problems accessing a spring bean with session scope from a composer's event handler. Any insights on what I'm doing wrong would be most appreciated. The exception that occurs is listed below after the code examples. For this test I'm using ZK v3.5.1 with Tomcat v5.5 and Spring 2.0.8.

Thanks,
Dave

Spring-relevant extracts from my web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring/InteractiveAnalysis.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


The session bean as defined in the spring configuration file:

<bean id="SessionBean" class="com.test.SessionBeanImpl" scope="session">
</bean>


The contents of the composer's zul file:

<zk
xmlns="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://www.zkoss.org/2005/zk/annotation"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

<window
id="openTemplate"
title="Open Template"
border="normal"
width="240px"
apply="com.syntricity.interactiveanalysis2.zk.web.OpenTemplateController">
<vbox spacing="1em" valign="center">
<label value="" style="font-weight: bold" />
<hbox spacing="1em">
<label value=" "/>
<listbox width="210px" id="openTemplateListbox" multiple="false" droppable="false"
rows="6" >
<listhead>
<listheader id="openTemplateListTitle" label="Templates" sort="auto"/>
</listhead>
<listitem label="${each.name}" value="${each}" tooltiptext="${each.description}" forEach="${arg.openTemplateList}"/>
</listbox>
</hbox>
<hbox spacing="1em">
<label value=" "/>
<button width="60px" id="okOpen" label="OK" forward="onClick=onOk" />
<button width="60px" id="cancelOpen" label="Cancel" forward="onClick=onCancel" />
</hbox>
</vbox>

</window>
</zk>

The java file for the OpenTemplateController composer:

public class OpenTemplateController extends GenericComposer
{
private Window m_openTemplate;
private SessionInfo m_sessionInfo;

/**
* Store reference to window.
*
* @param window
* @throws Exception
*/
public void doAfterCompose( Component window ) throws Exception
{
super.doAfterCompose( window );

m_openTemplate = (Window)window;

m_sessionInfo = SessionInfoUtil.getSessionObject( window.getDesktop().getSession() );
}

/**
* Open template selected by user.
*/
public void onOk()
{
ApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext)m_openTemplate.getDesktop().getWebApp().getNativeContext());
SessionBean m_sessionBean = (SessionBean)ctx.getBean("SessionBean"); // <-- causes exception
}
}


The exception that occurs when attempting to get the SessionBean:

SEVERE: >>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionBean': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
>>java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
>> at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:102)
>> at org.springframework.web.context.request.SessionScope.get(SessionScope.java:88)
>> at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:283)
>> at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
>> at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:757)
>> at com.syntricity.interactiveanalysis2.zk.web.OpenTemplateController.onOk(OpenTemplateController.java:77)

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest
link publish delete flag offensive edit

answered 2008-11-06 20:27:17 +0800

DaveWild gravatar image DaveWild
18 1

Thanks, that was the information I needed!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-11-04 21:55:51 +0800

Seen: 1,866 times

Last updated: Nov 06 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More