-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi.
Can i get a Session atribute inside a Eventqueue ?
Example:
private void refreshQueue()
{
if ( !EventQueues.exists( "longop", EventQueues.SESSION ) )
{
EventQueue eq = EventQueues.lookup( "longop", EventQueues.SESSION, true ); //create a queue
Sessions.getCurrent().setAttribute( "test", "testing...." ); // set a attribute in a Session
//subscribe async listener to handle long operation
eq.subscribe(
new EventListener()
{
public void onEvent( Event evt )
{ //asynchronous
//(String)Sessions.getCurrent().getAttribute( "test" ) ; // Here is the problem. Try to get the attribute
org.zkoss.lang.Threads.sleep( 3000 ); //simulate a long operation
}
},
new EventListener()
{ //callback
public void onEvent( Event evt )
{
EventQueues.remove( "longop",EventQueues.SESSION );
}
}
);
eq.publish( new Event( "whatever" ) ); //kick off the long operation
}
else
{
print( "It is busy. Please wait" );
}
}
Asked: 2011-03-29 12:28:00 +0800
Seen: 172 times
Last updated: Mar 29 '11