You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Bernhard Huemer (JIRA)" <de...@myfaces.apache.org> on 2007/11/06 23:18:50 UTC

[jira] Created: (MYFACES-1761) Handling PostConstruct annotations - wrong order

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
             Fix For: 1.2.1-SNAPSHOT


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://mail-archives.apache.org/mod_mbox/myfaces-users/200711.mbox/%3c13613691.post@talk.nabble.com%3e). 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Paul McMahan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12543607 ] 

Paul McMahan commented on MYFACES-1761:
---------------------------------------

Feedback from the MyFaces dev list indicates that changing the LifecycleProvider interface in a maintenance release will be OK.

During that conversation Bernhard offered to provide an alternative patch that will bring together the best aspects of both patches already proposed for this issue.  Specifically, his proposal is:

{quote}
what about introducing "InjectionTasks"? The ManagedBeanBuilder, for example, could register an InjectionTask that handles the injection of managed properties. In fact, I'm thinking of a more general approach of your patch so that others can perform additional injection too.

public interface InjectionTask {

    public void inject(Object bean) throws ...;

}
{quote}

See http://www.nabble.com/Re%3A-external-api-change-OK-for-myfaces-impl-1.2.1--p13733556.html

> 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
>            Assignee: Paul McMahan
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: MYFACES-1761-01.diff, 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Antoni Reus (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12621786#action_12621786 ] 

Antoni Reus commented on MYFACES-1761:
--------------------------------------

Is this planned for 1.2.4?

> 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
>            Assignee: Paul McMahan
>         Attachments: MYFACES-1761-01.diff, 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Martin Marinschek (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541298 ] 

Martin Marinschek commented on MYFACES-1761:
--------------------------------------------


@Paul: I think we should do the same as the RI does (especially, as what the RI does is a lot more inline with what a user would expect). 

We need to be compliant not only to the spec wording, but also to the meaning, and the meaning is interpreted by what the RI does (we can certainly behave different if compatiblity is not at stake and if we do things better for the user, but not worse). So this is indeed a bug!

regards,

Martin

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12553443 ] 

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

deffered to 1.2.2

> 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
>            Assignee: Paul McMahan
>             Fix For: 1.2.2-SNAPSHOT
>
>         Attachments: MYFACES-1761-01.diff, 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.


[jira] Updated: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Bernhard Huemer (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bernhard Huemer updated MYFACES-1761:
-------------------------------------

    Status: Patch Available  (was: Open)

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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://mail-archives.apache.org/mod_mbox/myfaces-users/200711.mbox/%3c13613691.post@talk.nabble.com%3e). 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "David Jencks (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540615 ] 

David Jencks commented on MYFACES-1761:
---------------------------------------

I'm not sure you have your environment configured correctly to handle dependency injection.  If I've located the post correctly the last few lines indicate that you are using

org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider.newInstance

which by its name is unlikely to do any dependency injection.  Also the text indicates tomcat 5 whereas the stack trace appears to show jetty.  I'm not sure either tomcat or jetty < 6 support any dependency injection under any circumstances.  I'm not sure of the level of support for jsf dependency injection in tomcat and jetty 6 standalone either.  It's possible you may need to run in a javaee 5 app server such as geronimo to have the jndi setup to support the dependency injection.

In any case the intent of the LifecycleProvider interface is that newInstance
1. creates the object
2. injects dependencies
3. calls the PostConstruct lifecycle methods.

thus handling all aspects of making the bean ready for use.  This allows you to easily plug in all sorts of strategies without making assumptions about exactly what is going on.  For instance in geronimo we are using a library that can potentially support constructor dependency injection, but does steps 1 and 2 in one  method call.  For this reason I am strongly against separating 1 and 2 into separate calls.

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
    [ 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.


[jira] Updated: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Leonardo Uribe updated MYFACES-1761:
------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.2.7-SNAPSHOT
         Assignee: Leonardo Uribe
           Status: Resolved  (was: Patch Available)

> 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
>            Assignee: Leonardo Uribe
>             Fix For: 1.2.7-SNAPSHOT
>
>         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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Paul McMahan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541068 ] 

Paul McMahan commented on MYFACES-1761:
---------------------------------------

Bernhard,  thanks for bringing this up and for the helpful sample which clearly demonstrates the issue.

Can you please point me to the language in the spec that you are referring to?   Specifically you said:
"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."

But the language I found in the spec says:
"JSF implementations running in a Java EE 5 compliant container must support attaching the @PostConstruct and @PreDestroy annotations to aid in awareness of the managed-bean lifecycle."
    and
"Methods on managed beans declared to be in request, session, or application scope, annotated with @PostConstruct, must be called by the JSF implementation after resource injection is performed (if any) but before the bean is placed into scope."

Reading the spec literally, the @PostConstruct annotation is exclusively provided for the benefit of resource injection in a Java EE 5 container, which as you have pointed out doesn't necessarily know about managed bean properties.  I don't see any discussion about the @PostConstuct annotation being related to managed bean properties, so initializing them before calling @PostConstrcut could arguably be non-compliant with the spec.  (I'm not taking that position, just considering both sides)

I agree that initializing managed properties before calling PostConstruct methods might be a useful feature worth further consideration.  But I want to determine first whether we think it is actually required by the spec or its up to us to determine if/how this feature should be implemented.

If it's not required by the spec then let's consider how the RI behaves.  Something I read in a blog suggests that the RI does in fact provide this feature, which would make me lean towards also providing it in MyFaces.  However, the LifeCycleProvider interface you modified is an existing integration point for servlet and Java EE containers, and there are very similar LifeCycleProvider interfaces for several other Java EE components.   So let's investigate whether it's possible to provide this feature without changing the interface, perhaps by refactoring the ManagedBeanBuilder so that initialization can occur as an additional step within the LifeCycleProvider.newInstance().

Looking forward to your thoughts on all this!

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Paul McMahan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541154 ] 

Paul McMahan commented on MYFACES-1761:
---------------------------------------

The original description for this issue says:   "The specification states that... after the object is initialized and after dependency injection is performed"

But your quote from the spec says:  "after the object is *instantiated*, and after injection is performed"

I take this change in your terminology as agreement that creating (instantiating) the bean does not involve setting its managed properties, correct?  Now it seems that you are instead interpreting the term "injection" to include setting of managed properties from the application config file.   But I would have to disagree with that position as well because section 5.4 says (with *emphasis* added by me) :

"JSF Implementations that are running as a part of Java EE 5 must allow managed bean 
implementations to use the annotations specified in section 14.5 of the Servlet 2.5 
Specification to allow the container to inject references to *container managed resources* into 
a managed bean instance before it is made accessible to the JSF application."

The spec goes on to provide the concise list of annotations where injection is valid - @Resource, @EJB, @WebService, etc.   I see no other discussion of injection in the JSF spec.  While I can understand your practical usage of this term to include setting of managed properties, IMO that usage is not consistent with the spec which is very clear about injection being limited to a specific list of annotations for referencing container managed resources.

I still agree with you that making this change could be appropriate and I think that consistency with the RI is important as well.  Earlier when I mentioned the RI I meant Glassfish and not the JSF RI in a standalone servlet container.   The JSF spec only discusses dependency injection in JavaEE.   Which environment did you test the attached sample in?

Your reaction towards my suggestion for keeping the LifecycleProvider interface unchanged is on track with the reason I hope we can agree that we are discussing a feature request and not a myfaces bug.   If setting managed properties before calling @PostConstruct is *not* required by the spec, then 3rd party implementations of LifecycleProvider are not required to do it.  They can (optionally) use a refactored ManagedBeanBuilder api to initialize the managed bean or even process the application config file themselves.   Apache Geronimo would probably do the latter.

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Bernhard Huemer (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540625 ] 

Bernhard Huemer commented on MYFACES-1761:
------------------------------------------

Well, I'm not talking about full-fledged dependency injection (i.e. processing @Resource or @EJB annotations, ..), but rather about "managed property injection". A LifecycleProvider can't return beans ready for use as these dependencies are still missing. However, a LifecycleProvider can't inject them itself (or at least it shouldn't) as that's something that the ManagedBeanBuilder is responsible for.

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Bernd Bohmann (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540699 ] 

Bernd Bohmann commented on MYFACES-1761:
----------------------------------------

Bernhard, i think your patch is right. 
postConstruct should called after LifecycleProvider and ManagedBeanBuilder has injected all properties. 
If you changed the LifecycleProvider Interface, please send a information to the Geronimo people about the change. 

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Bernhard Huemer (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541122 ] 

Bernhard Huemer commented on MYFACES-1761:
------------------------------------------

In fact, I've even quoted the specification - Page 11, Spec Issue 119: "Specified that implementations running in a JSR-250 compliant container have their managed bean methods annotated with @PostConstruct be called after the object is instantiated, and after injection is performed, but before the bean is placed into scope. Specified that methods annotated with @PreDestroy be called when the scope for the bean is ending."

Additionally, the InjectionProvider interface, the RI's counterpart to our LifecycleProvider, has always seperated injection and "postconstruction". There is only one difference between those interfaces (of course, I'm referring to the "patched" version of the LifecycleProvider interface), the LifecycleProvider interface does support constructor injection whereas the InjectionProvider interface doesn't. I've also tested the postconstruct-demo using the RI and it behaves as I'd expect it - the method annotated with @PostConstruct is called after all properties (including JSF managed ones) have been injected. 

However, I don't think that it's possible to fix this "bug" without changing the LifecycleProvider interface. Of course, you could refactor some internal classes in order to involve the ManagedBeanBuilder in initializing the bean, but I wouldn't recommend it. The problem with this "fix" is that it wouldn't work with 3rd party implementations as you're required to refactor all implementations (i.e. you're introducing a breaking change even without changing the interface itself). 

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Paul McMahan (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541341 ] 

Paul McMahan commented on MYFACES-1761:
---------------------------------------

Thanks Martin.  As you can probably tell (and maybe agree?) I am still not convinced by the original claim that the current @PostConstruct support in MyFaces is not compliant with the wording in the JSF spec.  In fact I could go so far as to say that changing the current behavior actually introduces a bug because the spec is clear about injection (and therefore the timing of @PostConstruct) being limited to container managed resources.

So like you pointed out our next recourse is to look at the TCK and the RI for enlightenment.  MyFaces 1.2 passed the TCK so we are OK there.  But I don't think that the JSF RI (by itself) can be used to determine the meaning of this language in the spec because IIUC the JSF RI only provides the "hooks" for dependency injection.

Therefore my position is that it is the responsibility of the embedder of MyFaces to ensure compatibility with the *glassfish* RI, and compatibility with glassfish is not the responsibility of MyFaces itself.  Testing the JSF RI's resource injection behavior outside of a compliant JavaEE container (such as in tomcat or jetty) is not valid IMHO.

MyFaces can help JavaEE containers meet this compatibility requirement by refactoring ManagedBeanBuilder.  And furthermore MyFaces can provide (as a feature) default implementations of LifecycleProvider for various non-JavaEE environments that include this functionality.

My hope is that we can implement this @PostConstruct behavior while keeping the LifecycleProvider interface intact.   LifecycleProvider.newInstance() is the integration point for dependency injection in several JavaEE components in Geronimo, and I do not think that it is necessary to change that interface to provide the desired behavior.

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Bernhard Huemer (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541363 ] 

Bernhard Huemer commented on MYFACES-1761:
------------------------------------------

I guess I have to agree that the specification leaves room to interpretation and I understand your point of view, but I wouldn't go so far as you. In fact I didn't even thought of it as your intepretation seems rather farfetched to me (sorry ;-)), especially if I'm considering the specification issue discussion. Ed Burns proposed the following: "1. call any public no argument managed bean methods annotated with @PostConstruct be called after the object is instantiated, and after *any* injection is performed, but before the bean is placed into the scope."

Besides that, I don't understand why you're strongly objecting to changing the interface. LifecycleProvider.newInstance() remains to be a perfect integration point for injecting serveral JavaEE components. My proposed patch shows how easy it is to refactor a "typical" implementation (I know that it has not been a full-fledged JavaEE container, but I think it's actually the same - just a simple "processAnnotations" method call).

> 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
>             Fix For: 1.2.1-SNAPSHOT
>
>         Attachments: 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.


[jira] Commented: (MYFACES-1761) Handling PostConstruct annotations - wrong order

Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12667082#action_12667082 ] 

Matthias Weßendorf commented on MYFACES-1761:
---------------------------------------------

Paul, Bernd what is the sate of this patch ? Ever got a final decision ?

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