You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Stas Ostapenko <st...@gmail.com> on 2008/02/25 12:37:10 UTC
MyFaces @PostConstruct and DI issue
Hi !
I'm playing with @PostConstruct annotation and JSF. In fact I'm
following this article
http://weblogs.java.net/blog/jhook/archive/2007/05/jsf_12_ri_backi.html
. With Sun RI implementation all is working just fine, but not with
MyFaces. I'm a little bit confused. I've noticed that PostConstruct
annotated method is executed before request param is injected.
The source code I'm plaing with is
http://svn.apache.org/repos/asf/myfaces/current12/test-webapp, so
MyFaces version is 1.2.3-SNAPSHOT
public class HelloWorldBacking {
....
private Integer pid; //injected request param
public Integer getPid()
{
return this.pid;
}
public void setPid(Integer pid)
{
this.pid = pid;
}
@PostConstruct()
public void postConstruct() {
System.out.println("Injected request param : "+pid);
}
.....
}
<managed-bean>
<managed-bean-name>helloWorldBacking</managed-bean-name>
<managed-bean-class>org.apache.myfaces.blank.HelloWorldBacking</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>pid</property-name>
<property-class>java.lang.Integer</property-class>
<value>#{param.pid}</value>
</managed-property>
</managed-bean>
Any ideas ?
Re: MyFaces @PostConstruct and DI issue
Posted by Martin Marinschek <ma...@gmail.com>.
Hi Curtiss,
I don't think Bernhard ever got around to commit something which works
based on the discussion he had with Paul. Do you have a patch which
takes this into consideration?
@Bernhard: please, if you can spare a few hours, it would be great if
you could close this out...
regards,
Martin
On 2/25/08, Curtiss Howard <cu...@jprojects.net> wrote:
> Hi Stas,
>
> I'm not a MyFaces developer, but I believe this is a legitimate, major
> issue. I was able to reproduce this problem and what's happening is
> MyFaces is creating the bean, doing resource injection, calling the
> @PostConstruct method, and _then_ injecting managed properties. The
> article you linked makes it very clear that MyFaces needs to create the
> bean, perform resource AND managed property injection, and then call the
> @PostConstruct method:
>
> "But the flow within the JSF 1.2 RI for instantiating managed beans is
> as follows:
>
> 1. New the bean declared using the default constructor
> 2. Inject any |@Resource| declarations
> 3. Assign any managed-properties declared, cascading this process if
> new beans are referenced
> 4. Call |@PostConstruct| on the bean if declared
> 5. Store the bean in the correct scope and return"
>
> I have a working patch for this problem if one of the devs would like to
> weigh in with their opinion about opening a JIRA issue for this problem
> I'd be happy to provide it.
>
>
> Curtiss Howard
>
--
http://www.irian.at
Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German
Professional Support for Apache MyFaces
Re: MyFaces @PostConstruct and DI issue
Posted by Stas Ostapenko <st...@gmail.com>.
Thanks for help !
JIRA is my friend for last two days :) It's not only JSF related.
On Mon, Feb 25, 2008 at 4:45 PM, Curtiss Howard <cu...@jprojects.net> wrote:
> Well, I guess that's why it pays to spend a few minutes looking on JIRA ;).
>
>
>
>
> Gerald Müllan wrote:
> > Hi,
> >
> > this issue was already discussed under
> >
> > https://issues.apache.org/jira/browse/MYFACES-1761
> >
> > cheers,
> >
> > Gerald
> >
> > On Mon, Feb 25, 2008 at 3:24 PM, Curtiss Howard <cu...@jprojects.net> wrote:
> >
>
Re: MyFaces @PostConstruct and DI issue
Posted by Curtiss Howard <cu...@jprojects.net>.
Well, I guess that's why it pays to spend a few minutes looking on JIRA ;).
Gerald Müllan wrote:
> Hi,
>
> this issue was already discussed under
>
> https://issues.apache.org/jira/browse/MYFACES-1761
>
> cheers,
>
> Gerald
>
> On Mon, Feb 25, 2008 at 3:24 PM, Curtiss Howard <cu...@jprojects.net> wrote:
>
Re: MyFaces @PostConstruct and DI issue
Posted by Gerald Müllan <gm...@apache.org>.
Hi,
this issue was already discussed under
https://issues.apache.org/jira/browse/MYFACES-1761
cheers,
Gerald
On Mon, Feb 25, 2008 at 3:24 PM, Curtiss Howard <cu...@jprojects.net> wrote:
> Hi Stas,
>
> I'm not a MyFaces developer, but I believe this is a legitimate, major
> issue. I was able to reproduce this problem and what's happening is
> MyFaces is creating the bean, doing resource injection, calling the
> @PostConstruct method, and _then_ injecting managed properties. The
> article you linked makes it very clear that MyFaces needs to create the
> bean, perform resource AND managed property injection, and then call the
> @PostConstruct method:
>
> "But the flow within the JSF 1.2 RI for instantiating managed beans is
> as follows:
>
> 1. New the bean declared using the default constructor
> 2. Inject any |@Resource| declarations
> 3. Assign any managed-properties declared, cascading this process if
> new beans are referenced
> 4. Call |@PostConstruct| on the bean if declared
> 5. Store the bean in the correct scope and return"
>
> I have a working patch for this problem if one of the devs would like to
> weigh in with their opinion about opening a JIRA issue for this problem
> I'd be happy to provide it.
>
>
> Curtiss Howard
>
--
http://www.irian.at
Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German
Professional Support for Apache MyFaces
Re: MyFaces @PostConstruct and DI issue
Posted by Curtiss Howard <cu...@jprojects.net>.
Hi Stas,
I'm not a MyFaces developer, but I believe this is a legitimate, major
issue. I was able to reproduce this problem and what's happening is
MyFaces is creating the bean, doing resource injection, calling the
@PostConstruct method, and _then_ injecting managed properties. The
article you linked makes it very clear that MyFaces needs to create the
bean, perform resource AND managed property injection, and then call the
@PostConstruct method:
"But the flow within the JSF 1.2 RI for instantiating managed beans is
as follows:
1. New the bean declared using the default constructor
2. Inject any |@Resource| declarations
3. Assign any managed-properties declared, cascading this process if
new beans are referenced
4. Call |@PostConstruct| on the bean if declared
5. Store the bean in the correct scope and return"
I have a working patch for this problem if one of the devs would like to
weigh in with their opinion about opening a JIRA issue for this problem
I'd be happy to provide it.
Curtiss Howard