thx thomas for fast reply,

the problem is indeed that two instances are created one " 
PlaceHistoryMapperWithFactory<TokenizerFactory> " instance and one 
instances where constructors inject "AppPlaceHistoryMapper" (this one has 
null factory). 
But how to fix this? Your suggested provides-Code shouldn't change 
anything, should it?
So I tried your 2nd suggestion:
plus this in module:

>         bind(new 
>> TypeLiteral<PlaceHistoryMapperWithFactory<TokenizerFactory>>() {
>
>         }).to(AppPlaceHistoryMapper.class).in(Singleton.class);
>
> *It is working! *
But with this every user of AppPlaceHistoryMapper get a different instance 
- (i guess this is not really a problem) - is it possible to get/bind a 
singleton. 
Is it possible to bind AppPlaceHistoryMapper 
and  PlaceHistoryMapperWithFactory<TokenizerFactory> to the same instance 
of generated  AppPlaceHistoryMapper Impl?

On Tuesday, 22 May 2012 11:06:31 UTC+2, Thomas Broyer wrote:
>
>
>
> On Tuesday, May 22, 2012 10:55:15 AM UTC+2, tanteanni wrote:
>>
>> I am using "PlaceHistoryMapperWithFactory" as suggested 
>> here<http://stackoverflow.com/questions/10089964/places-that-share-all-but-prefix-or-how-to-use-placehistorymapperwithfactory>.
>>  
>> The factory is set within my "ClientModule" (gin):
>>
>>     @Provides
>>>
>>>     @Singleton
>>>
>>>     @Inject
>>>
>>>     public final PlaceHistoryMapperWithFactory<TokenizerFactory> 
>>>> getPlaceHistoryMapper(AppPlaceHistoryMapper hm,
>>>
>>>                                                                         
>>>>                TokenizerFactory tf) {
>>>
>>>         hm.setFactory(tf);
>>>
>>>         return hm;
>>>
>>>     }
>>>
>>>
>> I watched the code with debugger (Breakpoints on two lines above and on 
>> "NullPointerException"): 
>> 1. The factory is set within  "AbstractPlaceHistoryMapper<F>" and "hm" 
>> with set factory is returned
>> 2. AppPlaceHistoryMapperImpl throws NPEx at "return new 
>> PrefixAndToken("ContentMenu", factory.contentMenuPlace().getToken(place));" 
>> because factory is null
>>
>> What is going wrong here?
>>
>> One probably important thing: This problem is only (re)producible in 
>> hosted mode. If app is deployed it works fine!
>>
>
> Are you sure you're having the same AppPlaceHistoryMapper instance in both 
> places?
>
> If I were you, I'd rather write my module as:
> @Provides @Singleton
> PlaceHistoryMapperWithFactory<TokenizerFactory> 
> providePlaceHistoryMapper(TokenizerFactory tf) {
>    PlaceHistoryMapperWithFactory<TokenizerFactory> hm = 
> GWT.create(AppPlaceHistoryMapper.class);
>    hm.setFactory(tf);
>    return hm;
> }
>
> Alternatively, you can also remove that method entirely and simply 
> override and annotate the setFactory method in your AppPlaceHistoryMapper 
> interface:
> public interface AppPlaceHistoryMapper extends 
> PlaceHistoryMapperWithFactory<TokenizerFactory> {
>    @Inject
>    void setFactory(TokenizerFactory tf);
> }
> That will work with GIN (would fail with Guice though); see 
> http://code.google.com/p/google-web-toolkit/issues/detail?id=6151#c4
>
> (BTW, why is your method annotated with @Inject?)
>
> As for the difference between DevMode and prod mode, you should probably 
> file a bug on GIN.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/SVozo5IMmVYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to