Help

Controls

PermLinkWikiLink
Switch Workspace

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
12. Mar 2010, 11:37 America/New_York | Link

hi, i am working on Seam component events i am getting the output with the help of annotations.

Now i want to add the component Programatically and want to add as obsesrver for existing events. i.e registering component as observer dynamaically. without using annotations.

Any ideas?????????

Thanks in advance.

Regards Devika.N

3 Replies:
12. Mar 2010, 12:34 America/New_York | Link

I am not sure if this will work. But you can try this:

Init.instance().addObserverMethod(eventType, method, component, create)
12. Mar 2010, 12:38 America/New_York | Link

Thanks for the reply.

pls can u send me some sample code.

Regards Devika.N

12. Mar 2010, 12:54 America/New_York | Link

I just did.

You just need to fill out whatever you want.

This is taken from Component.java (source of seam) There you see how observers are registered using reflection

if ( method.isAnnotationPresent(Observer.class) )
      {
         //can't use Init.instance() here because of unit tests
         Init init = (Init) applicationContext.get(Seam.getComponentName(Init.class));
          
         Observer observer = method.getAnnotation(Observer.class);
         for ( String eventType : observer.value() )
         {
            if ( eventType.length()==0 ) eventType = method.getName(); //TODO: new defaulting rule to map @Observer onFooEvent() -> event type "fooEvent"
            init.addObserverMethod( eventType, method, this, observer.create() );
         }
      }