I tried out Matt's solution and it works well (as a short term fix until I
can redesign the application). The exact syntax was
EmailController ectrl = (EmailController)
facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,
"emailController");
Thanks a million, - Dave
Matt.Rossner-prest wrote:
>
> I agree with the others that it's better to redesign the application,
> however it's possible to access a managed bean as long as you can have the
> faces context available.
>
>
>
> You need to do something like this, I don't remember the exact syntax...
>
>
>
> facesContext.getApplication().getVariableResolver().resolveVariable("#{myManagedBean}");
>
>
>
> Calling resolve variable will instantiate the bean and do initialize any
> variables defined in the faces-config. It's essentially the same as using
> it on a page. Since using on a page will eventually call the same method
> (resolveVariable).
>
>
>
> Matt Rossner
>
> Prestataire - Société OnePoint Technology
>
> +33 (1) 41 24 62 66
>
>
>
> -----Original Message-----
> From: laredotornado [mailto:[email protected]]
> Sent: mercredi 25 novembre 2009 17:22
> To: [email protected]
> Subject: Re: AW: Possible to force bean to load into session at session
> start up?
>
>
>
>
>
> There may certainly be a design flaw and I definitely want to fix that at
>
> some point. But for now, regarding your comment ...
>
>
>
>> I guess it is possible
>
>
>
> How?
>
>
>
> Thanks, - Dave
>
>
>
>
>
>
>
> Rene Guenther wrote:
>
>>
>
>> Hi Dave,
>
>>
>
>> I guess it is possible. I just wanted to point out though that on a first
>
>> glance it looks like a design flaw. In my opinion a managed bean should
>
>> always be related to a JSF page. If it is not related, it should not be
>
>> declared as a bean of the presentation layer.
>
>> Eg. a bean responsible for email sending and receiving is a bean that
>
>> could
>
>> be used without a presentation layer (eg. in a scheduled background
>
>> process).
>
>>
>
>> Cheers
>
>> Rene
>
>>
>
>>
>
>> -----Ursprüngliche Nachricht-----
>
>> Von: laredotornado [mailto:[email protected]]
>
>> Gesendet: Mittwoch, 25. November 2009 17:05
>
>> An: [email protected]
>
>> Betreff: Possible to force bean to load into session at session start up?
>
>>
>
>>
>
>> Hi,
>
>>
>
>> I'm using MyFaces 1.1.6. I have this declaration in my faces-config.xml
>
>> file ...
>
>>
>
>> <managed-bean>
>
>> <managed-bean-name>emailController</managed-bean-name>
>
>> <managed-bean-class>
>
>> myco.util.jsf.controller.EmailController
>
>> </managed-bean-class>
>
>> <managed-bean-scope>session</managed-bean-scope>
>
>> <managed-property>
>
>> <property-name>mailSession</property-name>
>
>> <property-class>java.lang.String</property-class>
>
>> <value>java:comp/env/mail/session</value>
>
>> </managed-property>
>
>> </managed-bean>
>
>>
>
>> What I am noticing, though, is that the bean is not actually placed into
>
>> the
>
>> session until I visit a JSF page that references the bean, like
>
>>
>
>> <h:inputHidden value="#{emailController.field1}" />
>
>>
>
>> I'm in a situation where I need to access the bean in a controller before
>
>> I
>
>> visit a page that references it. Does anyone know how to tell
>> MyFaces/JSF
>
>> to load the bean when the session starts?
>
>>
>
>> Thanks for all your help, - Dave
>
>>
>
>> --
>
>> View this message in context:
>
>> http://old.nabble.com/Possible-to-force-bean-to-load-into-session-at-session
>
>> -start-up--tp26515381p26515381.html
>
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>>
>
>>
>
>>
>
>
>
> --
>
> View this message in context:
> http://old.nabble.com/Possible-to-force-bean-to-load-into-session-at-session-start-up--tp26515381p26515686.html
>
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
>
>
>
--
View this message in context:
http://old.nabble.com/Possible-to-force-bean-to-load-into-session-at-session-start-up--tp26515381p26516658.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.