myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ingo Düppe <mailing-li...@dueppe.com>
Subject Re: managed-beans, spring references, and serializable
Date Mon, 25 Sep 2006 19:14:28 GMT
Hi Gerald,

as soon a have a running version, I will setup a wiki page :-)

But I still have some trouble to get the facescontext.

My FacesContext.getCurrentInstance() return null. Maybe something is 
wrong with my application.

I did the following steps:
1. Start my application.
2. Request some pages, so that my registrationController is initialized 
in SessionScope.
3. Shutdown Tomcat
4. Start Tomcat
5. Stops at my breakpoint in my readResolve() method.
6. FacesContext.getCurrentInstance() is null :-(

Any ideas?

Ingo

Gerald Müllan schrieb:
> Hi,
>
> you should be able to get the current instance to the facesContext
> like the other times.
>
> We retrieve the reference to springs BeanFactory like this:
>
> FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()) 
>
>
> Then you are able to get the bean you want to inject:
>
> Object newValue = beanFactory.getBean(propName);
>
> and can set it into the managed bean "o" with the property "propName":
>
> PropertyUtils.setSimpleProperty(o, propName, newValue);
>
> With the help of commons beanutils` "PropertyUtils" it is much easier.
>
> Hope this helps,
>
> cheers,
>
> Gerald
>
> On 9/25/06, Ingo Düppe <mailing-lists@dueppe.com> wrote:
>> Hi Gerald,
>>
>> this sound to be a smart little solution.
>> But how did you get the spring bean factory. At the point of
>> deserialization I don't have any FacesContext or ServletContext
>> reference to initialize the BeanFactory?
>>
>> Regards
>> Ingo
>>
>> Gerald Müllan schrieb:
>> > Hi,
>> >
>> > we have been faced with the same problem in our application.
>> >
>> > You have to take care that after deserialization the spring beans are
>> > injected the "normal" way. We did this by marking spring beans as
>> > transient, like you did:
>> >
>> > private transient ServiceBean _serviceBean;
>> >
>> > //Setter
>> >
>> > Letting serialize the spring bean only brings back some nonsense and
>> > no spring object you can deal with.
>> >
>> > So we implemented the method readResolve() (called after
>> > deserialization) in the managed bean:
>> >
>> > public Object readResolve() throws ObjectStreamException
>> > {
>> >   return TransientFieldsInjector.inject(this);
>> > }
>> >
>> > The injector has to get the bean from the spring BeanFactory and call
>> > the corresponding setter in the managed bean to inject it "manually".
>> > You have to do little reflection stuff, but only a few loc.
>> >
>> > Maybe there are also other solutions. We did it and it works very fine
>> > in combination
>> > with t:saveState.
>> >
>> > Hope this helps,
>> >
>> > cheers,
>> >
>> > Gerald
>> >
>> > On 9/25/06, Ingo Düppe <mailing-lists@dueppe.com> wrote:
>> >> Hi,
>> >>
>> >> I have a conceptional question. Within my application I define a
>> >> managed-bean "registrationController" that gets a reference to a 
>> spring
>> >> bean "registrationService" by the jsf property injection. The spring
>> >> bean is stateless and is not serializable, so I need to define the 
>> field
>> >> reference in "registrationController" as transient. This prevents 
>> me for
>> >> getting NotSerializableException.
>> >>
>> >> But what happens if the session is reloaded, will jsf reinject the
>> >> properties?
>> >> Is there any recommended way how to deal with this.
>> >>
>> >> The obvious way to make the service bean serializable doesn't seem to
>> >> work, because a whole data access layer is bound to the service bean.
>> >>
>> >> Or do I need to clearly separate. All managed-beans that have a
>> >> reference to the service layer need to be scoped as application (or
>> >> maybe as request) and only the value objects or entities are 
>> allowed to
>> >> be stored in the session scope.
>> >>
>> >> Regards,
>> >> Ingo
>> >>
>> >> Here is an example of my configuration:
>> >>     <managed-bean>
>> >>         <managed-bean-name>registrationController</managed-bean-name>
>> >>
>> >> 
>> <managed-bean-class>org.openuss.security.registration.RegistrationController</managed-bean-class>

>>
>> >>
>> >>         <managed-bean-scope>session</managed-bean-scope>
>> >>         <managed-property>
>> >>             <property-name>service</property-name>
>> >>             <value>#{registrationService}</value>
>> >>         </managed-property>
>> >>     </managed-bean>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
>
>


Mime
View raw message