Hi Daniil,

There is no simple way of accessing session in a TypeConverter. I've achieved 
this by using Spring with a session bean. Unfortunetly, I've been forced to do 
some hacking with Spring so it's context is saved in a static variable.
One you do this hack, simply have a TypeConverterFactory with:

public class SpringTypeConverterFactory extends DefaultTypeConverterFactory {

/**

* Add spring beans to converter.

*/

@Override

@SuppressWarnings("unchecked")

public TypeConverter getInstance(Class<? extends TypeConverter> clazz, Locale 
locale) throws Exception {

TypeConverter converter = super.getInstance(clazz, locale);

SpringConfig.injectBeans(converter);

return converter;

}

}


And you can use @Autowired in any TypeConverter.


For your information here's my SpringConfig class:

public class SpringConfig implements ApplicationContextAware {

private static Logger logger = LoggerFactory.getLogger(SpringConfig.class);

/**

* Spring ApplicationContext.

*/

private static ApplicationContext applicationContext;

/**

* Inject Spring dependence into bean.

* If bean was created by cglib, this method may not be able to set beans 
correctly.

* @param bean Object.

*/

public static void injectBeans(Object bean) {

AutowireCapableBeanFactory beanFactory = 
applicationContext.getAutowireCapableBeanFactory();

beanFactory.autowireBeanProperties(bean, 
AutowireCapableBeanFactory.AUTOWIRE_NO, false);

beanFactory.initializeBean(bean, bean.getClass().getSimpleName());

}

public void setApplicationContext(ApplicationContext context) {

applicationContext = context;

}

// Called as detroy-method.

public void close() {

applicationContext = null;

}

}

________________________________
From: Daniil Sosonkin [mailto:[email protected]]
Sent: Friday, June 05, 2009 3:34 PM
To: Stripes Users List
Subject: [Stripes-users] access session from a TypeConverter

Here's a good one. I have a TypeConverter that needs to access some variables 
for the current session. So far, I haven't found a way of doing that via 
library. I could be missing something. Can someone point me in the right 
direction?

Daniil
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to