GWT:使用延迟绑定将 AbstractPlaceHistoryMapper 替换为自定义映射器
看起来为 PlaceHistoryMapper 生成的类被硬编码为使用 AbstractPlaceHistoryMapper 作为超类。
因此,我试图通过尝试使用延迟绑定将 AbstractPlaceHistoryMapper 替换为我的自定义映射器来解决此问题。我在 *.gwt.xml 中使用以下规则:
<replace-with class="com.google.gwt.place.impl.AbstractPlaceHistoryMapper">
<when-type-is class="com.test.sampleapp.CustomPlaceHistoryMapper" />
</replace-with>
但由于某种原因,替换似乎没有发生。 CustomPlaceHistoryMapper 没有被启动,生成的类仍然使用 AbstractPlaceHistoryMapper。
非常感谢任何关于可能导致这种行为的想法/指示。
注意:我也在 GWT 组上发布了此问题,但到目前为止尚未收到答复。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使延迟绑定起作用,必须使用
GWT.create()
创建一个类。但是,AbstractPlaceHistoryMapper
仅用作扩展类。因此它永远不会通过 GWT.create 创建,而是始终通过实例化子类来创建。因此,延迟绑定在这种情况下不起作用。如果您想要完全不同的实现,则必须实现自定义PlaceHistoryMapper
,并自行管理已知标记。这也意味着您也无法使用历史注释。附带说明一下,规则中的类名应该交换。但对于最终结果来说,这并不重要,因为它一开始就行不通。
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 customPlaceHistoryMapper
, 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.
使用以下方法绝对可以拥有自定义历史记录令牌(例如,
#mail
或#mail/bla
而不仅仅是#mail:inbox
) GWT (2.0) 提供的开箱即用的与地点相关的类。您可以实例化默认的
PlaceHistoryMapper
,并在其构造函数中传递PlaceHistoryMapper
或PlaceHistoryMapperWithFactory的实现,而不是替换
。AbstractPlaceHistoryMapper
。例如:
然后您就可以根据需要映射令牌。
我个人建议您在映射器自定义实现中使用唯一的
PlaceTokenizer
,这样我就不必在每个 Place 中拥有内部 PlaceTokenizer 类>。希望有帮助。如有任何疑问,请随时提出。
It is absolutely possible to have custom history tokens (eg.
#mail
or#mail/bla
instead of only#mail:inbox
) using the out-of-the-box Place-related classes that GWT (2.0) provides.Instead of replacing
AbstractPlaceHistoryMapper
you could instantiate the defaultPlaceHistoryMapper
passing in it's constructor your implementation ofPlaceHistoryMapper<T>
orPlaceHistoryMapperWithFactory<T>
.eg.:
You will be able then to map tokens as you wish.
I personally recommend you to use an unique
PlaceTokenizer
in you mapper custom implementation so that I dont have to have an inner PlaceTokenizer class in each of your Places.Hope that helps. Feel free to ask any doubts.