Seam will fire different kinds of events that relate to particular scopes, tasks, or processes and appends the name of the scope, task or process to the end of the event.
Seam将触发与特定范围,任务或进程相关的不同类型的事件,并将范围,任务或进程的名称附加到事件的结尾。
How do I listen to all the events of a type?
我如何收听某类型的所有事件?
E.g. for any <name>
I'd like to listen to events such as these:
例如。对于任何
-
org.jboss.seam.createProcess.<name>
— called when the process is created -
org.jboss.seam.endProcess.<name>
— called when the process ends -
org.jboss.seam.initProcess.<name>
— called when the process is associated with the conversation -
org.jboss.seam.startTask.<name>
— called when the task is started -
org.jboss.seam.endTask.<name>
— called when the task is ended
org.jboss.seam.createProcess。
org.jboss.seam.endProcess。
org.jboss.seam.initProcess。
org.jboss.seam.startTask。
org.jboss.seam.endTask。
I need to do this despite not knowing the list of valid names up front... :-(
我需要做到这一点,尽管前面不知道有效名单列表...... :-(
I hope to be using @Observer to create the observer, or something similar, and I'll listen to up to two event classes in the same component.
我希望使用@Observer来创建观察者或类似的东西,我会在同一个组件中听到最多两个事件类。
2 个解决方案
#1
You can easily do this by replacing Seam's Events class with your own implementation. Then look for events that are raised that start with a particular string:
您可以通过将Seam的Events类替换为您自己的实现来轻松完成此操作。然后查找以特定字符串开头的引发事件:
@Scope(ScopeType.STATELESS)
@BypassInterceptors
@Name("org.jboss.seam.core.events")
@Install(precedence=APPLICATION)
public class Events extends org.jboss.seam.core.Events
{
@Override
public void raiseEvent(String type, Object... parameters )
{
super.raiseEvent( type, parameters );
if ( type.startsWith( "org.jboss.seam.createProcess" ) )
{
super.raiseEvent( "org.jboss.seam.createProcess", parameters );
}
//etc.
}
}
You can now observe "org.jboss.seam.createProcess" to get all createProcess events.
您现在可以观察“org.jboss.seam.createProcess”以获取所有createProcess事件。
#2
Inside the if, you must write super.raiseEvent(...) otherwise you'll get an infinite loop.
在if中,你必须编写super.raiseEvent(...),否则你将得到一个无限循环。
#1
You can easily do this by replacing Seam's Events class with your own implementation. Then look for events that are raised that start with a particular string:
您可以通过将Seam的Events类替换为您自己的实现来轻松完成此操作。然后查找以特定字符串开头的引发事件:
@Scope(ScopeType.STATELESS)
@BypassInterceptors
@Name("org.jboss.seam.core.events")
@Install(precedence=APPLICATION)
public class Events extends org.jboss.seam.core.Events
{
@Override
public void raiseEvent(String type, Object... parameters )
{
super.raiseEvent( type, parameters );
if ( type.startsWith( "org.jboss.seam.createProcess" ) )
{
super.raiseEvent( "org.jboss.seam.createProcess", parameters );
}
//etc.
}
}
You can now observe "org.jboss.seam.createProcess" to get all createProcess events.
您现在可以观察“org.jboss.seam.createProcess”以获取所有createProcess事件。
#2
Inside the if, you must write super.raiseEvent(...) otherwise you'll get an infinite loop.
在if中,你必须编写super.raiseEvent(...),否则你将得到一个无限循环。