[ 
https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12702075#action_12702075
 ] 

Leonardo Uribe commented on MYFACES-1761:
-----------------------------------------


 In few words, the problem is:

- LifecycleProvider interface is incomplete/insufficient to handle 
@PostConstruct annotations
- Both patches proposed changes LifecycleProvider interface in one way or 
another. Since this interface is an integration point to other Java EE5 
container (for example Geronimo), change it is not wanted.

 To solve this problem, another patch is proposed (MYFACES-1761-2.patch). It is 
a modification of the solution proposed in MyFaces-1761.patch, but preventing 
changes on LifecycleProvider. The idea  is simple: create a interface called 
LifecycleProvider2 with the "missing" postConstruct method. ManagedBeanBuilder 
do something like this:

public Object buildManagedBean(FacesContext facesContext, ManagedBean 
beanConfiguration) throws FacesException
{
        //..... get the LifecycleProvider instance......
        final Object bean = 
lifecycleProvider.newInstance(beanConfiguration.getManagedBeanClassName());   

        //....... inject properties........
        
        if (lifecycleProvider instanceof LifecycleProvider2)
        {
             ((LifecycleProvider2)lifecycleProvider).postConstruct(bean);
        }
        return bean;
}

In this way we preserve the old behavior (and integration code from outside 
myfaces), giving the option to solve this problem.

In version 2.0 we can correct LifecycleProvider and let LifecycleProvider2 just 
as backward compatibility, but in my personal opinion I prefer let it as is.

If no objections I'll commit the last patch.

> Handling PostConstruct annotations - wrong order
> ------------------------------------------------
>
>                 Key: MYFACES-1761
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1761
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions:  1.2.0, 1.2.1-SNAPSHOT
>            Reporter: Bernhard Huemer
>         Attachments: MYFACES-1761-01.diff, MYFACES-1761-2.patch, 
> MyFaces-1761.patch, postconstruct-demo.zip
>
>
> The specification states that managed bean methods annotated with 
> @PostConstruct have to be called after the object is initialized and after 
> dependency injection is performed. However, MyFaces calls those methods after 
> the bean instance is created but before dependency injection is performed 
> (for example, see 
> http://www.nabble.com/myfaces-1.2.0-postConstruct-tf4760326.html ). In order 
> to resolve this bug the LifecycleProvider interface has to be changed. 
> Currently there's only one method responsible for creating/initializing a new 
> bean: newInstance(). This design choice implicates that there's no 
> possibility to seperate the steps "creating the bean" and "postconstructing 
> the bean".

-- 
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