users@javaserverfaces.java.net

Re: At which Managed Bean Lifecycle Phase does Injection happen?

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Mon, 21 May 2007 08:06:37 -0700

Todd Patrick wrote:
> Ryan:
>
> OK. I see that I can do either:
>
> <f:view beforePhase="#{}">
>
> or
>
> <f:view afterPhase="#{}">
>
> Is this what you meant by attaching a PhaseListener to the view?
>
> I couldn't find anything else.
>
> Thanks,
>
Yes, that is what I was referring to.
> --Todd
>
> -----Original Message-----
> From: Ryan.Lubke_at_Sun.COM [mailto:Ryan.Lubke_at_Sun.COM]
> Sent: Saturday, May 19, 2007 10:59 AM
> To: users_at_javaserverfaces.dev.java.net
> Subject: Re: At which Managed Bean Lifecycle Phase does Injection
> happen?
>
> Todd Patrick wrote:
>
>> Ryan, Jacob:
>>
>> Thank you for the information, but I'm stuck with an logic issue.
>>
>> Once I inject my EJB with:
>>
>> @EJB private CustomerSessionLocal customerSessionRemote;
>>
>> Do I assign "customerSessionRemote" to a managed property? Such as:
>>
>> <managed-property>
>> <property-name>currentCustomer</property-name>
>>
>> <property-class>com.dtn.bean.customer.CustomerSessionLocal</property-c
>> la
>> ss>
>> <null-value/>
>> </managed-property>
>>
>> So I can access a method in my "customerSessionRemote" EJB reference?
>>
>> Bottom line is, I need:
>>
>> 1.) Inject or Lookup an EJB
>> 2.) Each time the page is loaded, call a method - pass a parameter to
>> the method - in the EJB to return a List. The list is used to populate
>>
>
>
>> a h:selectManyListbox.
>>
>>
> I'm assuming the parameters you wish to provide are coming from the
> request.
> If you want to do this each time the page is loaded, then you'll want to
> provide a PhaseListener and attach it to the view (this is a new feature
> added in 1.2 - check the tlddocs [1] for details).
>
> In your custom PL, you can lookup the ManagedBean, and then you can call
> some public method on the bean that passes the parameters to the EJB.
>
>> I can't used a method with the @PostConstruct annotation since that is
>>
>
>
>> only called once and I can't call that method again.
>>
>> The 'pass a parameter to the method' to an EJB method each time the
>> page is loaded is really throwing me for a loop.
>>
>> Once I have the EJB reference, I put the business logic in a void
>> return type method and made a reference to the method in the bean
>> constructor, but it throws a NullPointerException the first time the
>> page is loaded because the constructor runs before the EJB
>>
> injection...
>
>> Any thoughts on this?
>>
>> Thanks,
>>
>> --Todd
>>
>>
>>
>>
>> -----Original Message-----
>> From: jacob_at_hookom.net [mailto:jacob_at_hookom.net]
>> Sent: Friday, May 18, 2007 1:25 PM
>> To: users_at_javaserverfaces.dev.java.net
>> Subject: Re: At which Managed Bean Lifecycle Phase does Injection
>> happen?
>>
>> http://weblogs.java.net/blog/jhook/archive/2007/05/jsf_12_ri_backi.htm
>> l
>>
>>
>> Todd Patrick wrote:
>>
>>
>>> JSF 1.2_04
>>>
>>> At which Managed Bean Lifecycle Phase does Injection happen or does
>>> Injection happen after all of the Lifecycle Phases have completed?
>>>
>>>
>>>
>> Injection isn't associated with a phase, it will occur when the bean
>> is first referenced and not already in scope.
>>
>>
>>> If I inject an EJB with:
>>>
>>> @EJB private CustomerSessionLocal customerSessionRemote;
>>>
>>> I can do set-up with a method annotated with @PostConstruct, however
>>> I
>>>
>>>
>>
>>
>>> cannot use any parameters.
>>>
>>> I'd like to call a EJB method AND pass parameters each time the
>>> managed bean is loaded for the JSF page being called.
>>>
>>> What is happening is the annotated method is called once - thus any
>>> call to the page again still has the first call values, I need to
>>> pass
>>>
>>>
>>
>>
>>> different parameters based on the user's selections on the JSF page.
>>>
>>> JSF --> [parameters] -->
>>> Managed Bean --> [parameters] -->
>>> Injected EJB --> [parameters] --> EJB method
>>>
>>> Is this scenario possible and how?
>>>
>>>
>>>
>> If you use managed-properties, these would be initialized before the
>> @PostConstruct callback was invoked and thus be available for use.
>>
>>
>>> Thanks,
>>>
>>> --Todd
>>>
>>> -----------------------------------------
>>> NOTICE: This email message is for the sole use of the intended
>>> recipient(s) and may contain confidential and privileged information.
>>>
>
>
>>> Any unauthorized use, disclosure or distribution is prohibited. If
>>> you
>>>
>>>
>>
>>
>>> are not the intended recipient, please contact the sender by reply
>>> email and destroy all copies of the original message.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_javaserverfaces.dev.java.net
>>> For additional commands, e-mail:
>>> users-help_at_javaserverfaces.dev.java.net
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_javaserverfaces.dev.java.net
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_javaserverfaces.dev.java.net
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_javaserverfaces.dev.java.net
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
>