[ 
https://issues.apache.org/jira/browse/MYFACES-2509?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Leonardo Uribe reopened MYFACES-2509:
-------------------------------------


I have to reopen this issue. The reason is really I don't believe this code 
works, or anyone has tested it fully. Look this code carefully:

    private void processListenerFor(Application application, Class clazz, 
ListenerFor listenerFor)
    {
        try
        {
            if (SystemEventListener.class.isAssignableFrom(clazz))
            {
                Class sourceClass = listenerFor.sourceClass();
                Class<? extends SystemEvent> systemEventClass = 
listenerFor.systemEventClass();
                if (Void.class.equals(sourceClass))
                {
                    application.subscribeToEvent(systemEventClass, 
(SystemEventListener) clazz.newInstance());
                }
                else
                {
                    application.subscribeToEvent(systemEventClass, sourceClass, 
(SystemEventListener) clazz.newInstance());
                }
            }
        }
        catch (InstantiationException e)
        {
            throw new FacesException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new FacesException(e);
        }
    }

Do you see the clazz.newInstance()? This works for classes that does not have 
state, but what happen if we need some variable. Since the "real" is created 
somewhere else, the value will not be right. 

If we want to make this work, we have to scan for annotations after the 
instantiation and if we have a instance wrapping, we should scan properly. What 
happen if some user has a @ListenerFor for a PhaseListener? What happen is some 
user has a @ListenerFor for a Application/ViewHandler/StateManager instance? Do 
we need to do something for CDI?

The spec is silent about that, so the right way to solve this one is propose an 
algorithm and submit is first to jsr-314-open mail list, so the experts can 
take a look and decide what to do. Maybe we can propose something and do it on 
myfaces directly, since we are on beta yet, but the intention about do all this 
bureaucracy is keep as close with the spec as possible or in other words, make 
applications interchageable between jsf implementations.

Unfortunately, I have to revert this code, because I just can't do another beta 
release with this code on it.

> @ListenerFor not processed for global system events
> ---------------------------------------------------
>
>                 Key: MYFACES-2509
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2509
>             Project: MyFaces Core
>          Issue Type: New Feature
>          Components: JSR-314
>    Affects Versions: 2.0.0-alpha
>            Reporter: Jan-Kees van Andel
>            Assignee: Jan-Kees van Andel
>             Fix For: 2.0.0-beta-3
>
>         Attachments: ListenerFor_support.patch
>
>
> We currently don't process @ListenerFor and @ListenerFor annotations on 
> non-component types.
> This is specified in the spec for global system events, see:
> http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/index.html?javax/faces/event/ListenerFor.html
> It would be nice to have it in the beta.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to