-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Get username in EventListener to handle signature fields
PostPosted: Mon Feb 18, 2008 5:16 am 
Newbie

Joined: Fri Feb 15, 2008 10:48 am
Posts: 3
Hi everybody,

I'm working with a database model that has for each row the old style signature fields (insert & update user/date).

To handle that transparently I added a Component with the four fields to each entity. The responsability to populate these fields is left to an EventListener (PreInsert & PreUpdate).

As the EventListener has to be stateless, the username is stored in the http session.

My problem is how to get the username stored in the http session from the EventListener?

I tryed to make the EventListener statefull using a ThreadLocal to store the username at logon, but it's not the same thread as the one handling the request that is calling the listener.

Has someone any idea?

Thank you by advance.
Philippe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 4:09 am 
Newbie

Joined: Fri Feb 15, 2008 10:48 am
Posts: 3
Finally I found a way turning the EventListener in stateful mode using the new spring 2.5 scoped bean feature.

The EventListener has now a String property to hold the username. For each new http session spring creates a new EventListener instance. The property can be set at logon time.

Then spring injects dynamically at runtime the correct EventListener instance bound to the http session into the sessionFactory.

Here is the spring xml config:

<bean id="signatureHandler" scope="session"
class="test.SignatureEntityListener">
<aop:scoped-proxy/>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
...
</list>
</property>
<property name="eventListeners">
<map>
<entry>
<key>
<value>pre-insert</value>
</key>
<ref bean="signatureHandler" />
</entry>
<entry>
<key>
<value>pre-update</value>
</key>
<ref bean="signatureHandler" />
</entry>
</map>
</property>
<property name="hibernateProperties">
...
</property>
</bean>

That's it


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.