FAQ
Hey everyone,

I am integrating Spring into my JSF application, and had a question
about the lifecycle of a JSF managed bean.

I have a JSF managed bean that depends on a Spring managed bean. The
problem is that I need to do some initialization on the bean after it
has been created and *after the Spring Bean has been injected*.

Is there any way to define an init() method that gets invoked by JSF
after the properties have been set?

I am using the OOTB JSF integration piece that comes w/ Spring (not
the Spring-JSF project stuff... perhaps my problem is addressed
there?)

Thanks!
Dave

Search Discussions

  • Duncan Mills at Jun 17, 2005 at 12:11 am
    David, Could you not do the initialision in the setter that is being
    used to inject the Spring managed value?
    The other option would be to let Spring manage this object instead as
    you do have a lot more flexibilty there - however option 1 seems simpler
    if it would work in this situation..

    Duncan Mills
    www.groundside.com/blog

    David Tashima wrote:
    Hey everyone,

    I am integrating Spring into my JSF application, and had a question
    about the lifecycle of a JSF managed bean.I have a JSF managed bean that depends on a Spring managed bean. The
    problem is that I need to do some initialization on the bean after it
    has been created and *after the Spring Bean has been injected*.

    Is there any way to define an init() method that gets invoked by JSF
    after the properties have been set?

    I am using the OOTB JSF integration piece that comes w/ Spring (not
    the Spring-JSF project stuff... perhaps my problem is addressed
    there?)

    Thanks!
    Dave
  • David Tashima at Jun 17, 2005 at 1:26 am
    Yes, I was thinking about that, but it seemed a bit hacky to me -
    especially since it depends on the order that the properties are set.

    Actually, you're right - having Spring manage it works, since it has
    application scope anyway.

    So if the scope had to be something more transient than application
    scope, I would have to use the jsf-spring package?

    -Dave
    On 6/16/05, Duncan Mills wrote:
    David, Could you not do the initialision in the setter that is being
    used to inject the Spring managed value?
    The other option would be to let Spring manage this object instead as
    you do have a lot more flexibilty there - however option 1 seems simpler
    if it would work in this situation..

    Duncan Mills
    www.groundside.com/blog

    David Tashima wrote:
    Hey everyone,

    I am integrating Spring into my JSF application, and had a question
    about the lifecycle of a JSF managed bean.I have a JSF managed bean that depends on a Spring managed bean. The
    problem is that I need to do some initialization on the bean after it
    has been created and *after the Spring Bean has been injected*.

    Is there any way to define an init() method that gets invoked by JSF
    after the properties have been set?

    I am using the OOTB JSF integration piece that comes w/ Spring (not
    the Spring-JSF project stuff... perhaps my problem is addressed
    there?)

    Thanks!
    Dave
  • Duncan Mills at Jun 17, 2005 at 8:57 am
    Right if you want to have full control over the scope of Spring Managed Beans then you'll have to
    go with the more complete integration offered by the jsf-spring package. Although it's just
    occurred to me anther option might be customize DelegatingVariableResolver to make a
    callback to the bean, post-creation when the bean is manged by JSF. The only problem I can see
    with this (apart from the fact that you'll have extra code to maintain) is that the
    VariableResolver decorator will be called on any access to the bean via EL not just creation,
    so you'll have to add logic to somehow work out if this is creation or not - either in the bean
    itself which would be simplest - or in the decorator. Worth a thought.
    Duncan
    GroundBlog

    David Tashima wrote: Yes, I was thinking about that, but it seemed a bit hacky to me - especially
    since it depends on the order that the properties are set. Actually, you're right - having
    Spring manage it works, since it has application scope anyway. So if the scope had to be
    something more transient than application scope, I would have to use the jsf-spring package?
    -Dave On 6/16/05, Duncan Mills wrote: David, Could you not do the
    initialision in the setter that is being used to inject the Spring managed value? The other
    option would be to let Spring manage this object instead as you do have a lot more flexibilty
    there - however option 1 seems simpler if it would work in this situation.. Duncan Mills
    www.groundside.com/blog David Tashima wrote: Hey everyone, I am integrating Spring into my
    JSF application, and had a question about the lifecycle of a JSF managed bean.I have a JSF
    managed bean that depends on a Spring managed bean. The problem is that I need to do some
    initialization on the bean after it has been created and *after the Spring Bean has been
    injected*. Is there any way to define an init() method that gets invoked by JSF after the
    properties have been set? I am using the OOTB JSF integration piece that comes w/ Spring (not
    the Spring-JSF project stuff... perhaps my problem is addressed there?) Thanks! Dave
  • Cenk Çivici at Jun 17, 2005 at 6:37 am
    Spring DelegatingVariableResolver class can inject Spring Managed
    Beans to JSF Managed Beans. Havent tried this in myfaces but might
    work.

    Cenk Çivici
    www.jroller.com/page/cenkcivici

    1. Add the resolver to faces-config.xml

    <application>

    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>

    </application>

    2. A business delegate object "ReservationService" which is
    configured in Spring xml as follows.

    <bean id="reservationService" class="tbs.service.ReservationService">
    ...
    </bean>

    3. If you want to have this bean injected to your jsf managed bean
    during initialization you need to do the following.

    <managed-bean>
    <managed-bean-name>pc_reservationPage</managed-bean-name>
    <managed-bean-class>tbs.web.ReservationPage</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>reservationService</property-name>
    <value>#{reservationService}</value>
    </managed-property>
    </managed-bean>

    4. Last thing you need to have a setter in your jsf managed bean like

    public ReservationPage {

    protected IReservationService reservationService;

    public setReservastionService(IReservationService reservationService) {

    this.reservationService = reservationService;

    }

    ...

    ...

    }


    On 6/16/05, David Tashima wrote:
    Hey everyone,

    I am integrating Spring into my JSF application, and had a question
    about the lifecycle of a JSF managed bean.

    I have a JSF managed bean that depends on a Spring managed bean. The
    problem is that I need to do some initialization on the bean after it
    has been created and *after the Spring Bean has been injected*.

    Is there any way to define an init() method that gets invoked by JSF
    after the properties have been set?

    I am using the OOTB JSF integration piece that comes w/ Spring (not
    the Spring-JSF project stuff... perhaps my problem is addressed
    there?)

    Thanks!
    Dave
  • Jon Harley at Jun 17, 2005 at 11:21 am
    _________________________________________________________________
    Dr JW Harley Senior Technologist
    E-lab, IT Services Department, University of Warwick, Coventry UK
    <J.W.Harley@warwick.ac.uk> www.warwick.ac.uk/staff/J.W.Harley/
    davetash@gmail.com 06/17/05 02:19AM >>>
    Yes, I was thinking about that, but it seemed a bit hacky to me -
    especially since it depends on the order that the properties are set.
    You could always have ALL of the setters call your init method at
    the end, and have init return without action until all needed
    properties are present. It's not pretty but at least it's more
    robust.
    Actually, you're right - having Spring manage it works, since it has
    application scope anyway.
    So if the scope had to be something more transient than application
    scope, I would have to use the jsf-spring package?
    jsf-spring does allow you to use JSF scopes in Spring, yes. And it
    does work with MyFaces - as long as you take the broken
    faces-config.xml out of the jsf-spring.jar.


    Jon.
    On 6/16/05, Duncan Mills wrote:
    David, Could you not do the initialision in the setter that is being
    used to inject the Spring managed value?
    The other option would be to let Spring manage this object instead as
    you do have a lot more flexibilty there - however option 1 seems simpler
    if it would work in this situation..

    Duncan Mills
    www.groundside.com/blog

    David Tashima wrote:
    Hey everyone,

    I am integrating Spring into my JSF application, and had a question
    about the lifecycle of a JSF managed bean.I have a JSF managed bean that depends on a Spring managed bean. The
    problem is that I need to do some initialization on the bean after it
    has been created and *after the Spring Bean has been injected*.

    Is there any way to define an init() method that gets invoked by JSF
    after the properties have been set?

    I am using the OOTB JSF integration piece that comes w/ Spring (not
    the Spring-JSF project stuff... perhaps my problem is addressed
    there?)

    Thanks!
    Dave

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedJun 16, '05 at 6:41p
activeJun 17, '05 at 11:21a
posts6
users4
websitemyfaces.apache.org

People

Translate

site design / logo © 2019 Grokbase