Search code examples
gwthistorygwt-history

GWT: Replace AbstractPlaceHistoryMapper with a custom mapper using deferred binding


Looks like the class that is generated for PlaceHistoryMapper is hard-coded to use AbstractPlaceHistoryMapper as the super class.

So, I am trying to work around this by trying to replace this AbstractPlaceHistoryMapper with a custom mapper of mine using deferred binding . I am using the following rule in my *.gwt.xml:

<replace-with class="com.google.gwt.place.impl.AbstractPlaceHistoryMapper">
   <when-type-is class="com.test.sampleapp.CustomPlaceHistoryMapper" />
</replace-with>

But for some reason the replace does not seem to be happening. CustomPlaceHistoryMapper is not getting kicked in and the generated class still uses AbstractPlaceHistoryMapper.

Any thoughts/pointers as to what might be resulting this behavior are much appreciated.

Note: I have also posted this on the GWT group but haven't received an answer so far.


Solution

  • To make the deferred binding work a class must be created with GWT.create(). However, AbstractPlaceHistoryMapper is only used as an extended class. So it will never be created via GWT.create, but always by instantiation the subclass. And therefor deferred binding won't work in this case. If you want a complete different implementation you have to implement a custom PlaceHistoryMapper, and manage the known tokens yourself. This also means you can't use the History annotations either.

    As a side note the classnames in your rule should be swapped. But for the end result this doesn't matter, since it won't work in the first place.