履歴管理のアクティビティを使用せずにプレイスを使用する方法の例は誰にもあります。私はすぐに何かをノックし、ブラウザーバックとブラウザフォワードのクリックでURLが変化するのを見ることができますが、ディスプレイはどこにも行きません。GWT 2.1アクティビティのない場所の例
私はDecoratedTabPanelを使用しており、getPlaceController()。goTo(place)を起動するSelectionHandlerを持っています。
任意のアイデアが役に立ちます。
履歴管理のアクティビティを使用せずにプレイスを使用する方法の例は誰にもあります。私はすぐに何かをノックし、ブラウザーバックとブラウザフォワードのクリックでURLが変化するのを見ることができますが、ディスプレイはどこにも行きません。GWT 2.1アクティビティのない場所の例
私はDecoratedTabPanelを使用しており、getPlaceController()。goTo(place)を起動するSelectionHandlerを持っています。
任意のアイデアが役に立ちます。
ここでは、期待したことを示すために作成した簡単なコードを示します。これはGWTとMVP開発ドキュメント(GWT and MVP)に基づいています
この例では、2つのタブ間を移動します。選択すると、新しい履歴アイテムが作成されます(アクティビティなし)。ブラウザのボタンを使用して前後に移動する限り、ページは正しく更新されます。
私は1つの場所、1つのアクティビティとそのビューを定義しました。 AppActivityMapper、AppActivityManager、ClientFactoryを私のニーズに合わせて調整しました。コードは軽量であり、コメントを理解する必要はありません。私はそれが必要なときにいくつかの説明をしただけですが、明確でない場合は躊躇しないでください。
ExampleView.java
public interface ExampleView extends IsWidget {
void selectTab(int index);
}
ExampleViewImpl.java
public class ExampleViewImpl extends Composite implements ExampleView, SelectionHandler<Integer> {
private DecoratedTabPanel panel;
public ExampleViewImpl() {
panel = new DecoratedTabPanel();
initComposite();
initWidget(panel);
}
private void initComposite() {
panel.add(new HTML("Content 1"), "Tab 1");
panel.add(new HTML("Content 2"), "Tab 2");
panel.selectTab(0);
panel.addSelectionHandler(this);
}
@Override
public void selectTab(int index) {
if (index >=0 && index < panel.getWidgetCount()) {
if (index != panel.getTabBar().getSelectedTab()) {
panel.selectTab(index);
}
}
}
@Override
public void onSelection(SelectionEvent<Integer> event) {
// Fire an history event corresponding to the tab selected
switch (event.getSelectedItem()) {
case 0:
History.newItem("thetabplace:1");
break;
case 1:
History.newItem("thetabplace:2");
break;
}
}
}
ClientFactory.java
public class ClientFactory {
private final EventBus eventBus = new SimpleEventBus();
private final PlaceController placeController = new PlaceController(eventBus);
private final ExampleViewImpl example = new ExampleViewImpl();
public EventBus getEventBus() {
return this.eventBus;
}
public PlaceController getPlaceController() {
return this.placeController;
}
public ExampleViewImpl getExampleView() {
return example;
}
}
ExampleActivity.java
public class ExampleActivity extends AbstractActivity {
private ExampleView view;
private ClientFactory factory;
public ExampleActivity(ExamplePlace place, ClientFactory factory) {
// Get the factory reference
this.factory = factory;
// Get the reference to the view
view = this.factory.getExampleView();
// Select the tab corresponding to the token value
if (place.getToken() != null) {
// By default the first tab is selected
if (place.getToken().equals("") || place.getToken().equals("1")) {
view.selectTab(0);
} else if (place.getToken().equals("2")) {
view.selectTab(1);
}
}
}
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
// Attach this view to the application container
panel.setWidget(view);
}
}
ExamplePlace.java
/**
* Just an very basic place
*/
public class ExamplePlace extends Place {
// The token corresponding to an action
private String token;
// This place should use a token to identify a view behavior
public ExamplePlace(String token) {
this.token = token;
}
// Return the current token
public String getToken() {
return token;
}
// Custom prefix to break the default name : ExamplePlace
// So that the history token will be thetabplace:token
// and not any more : ExamplePlace:token
@Prefix(value="thetabplace")
public static class Tokenizer implements PlaceTokenizer<ExamplePlace> {
@Override
public String getToken(ExamplePlace place) {
return place.getToken();
}
@Override
public ExamplePlace getPlace(String token) {
return new ExamplePlace(token);
}
}
}
AppActivityMapper.java
public class AppActivityMapper implements ActivityMapper {
private ClientFactory clientFactory;
public AppActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}
@Override
public Activity getActivity(Place place) {
if (place instanceof ExamplePlace) {
return new ExampleActivity((ExamplePlace) place, clientFactory);
}
return null;
}
}
AppPlaceHistoryMapper.java
@WithTokenizers({ExamplePlace.Tokenizer.class})
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper
{
}
すべて一緒に
private Place defaultPlace = new ExamplePlace("1");
private SimplePanel appWidget = new SimplePanel();
public void onModuleLoad() {
ClientFactory clientFactory = new ClientFactory();
EventBus eventBus = clientFactory.getEventBus();
PlaceController placeController = clientFactory.getPlaceController();
// Start ActivityManager for the main widget with our ActivityMapper
ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
activityManager.setDisplay(appWidget);
// Start PlaceHistoryHandler with our PlaceHistoryMapper
AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
historyHandler.register(placeController, eventBus, defaultPlace);
RootPanel.get().add(appWidget);
// Goes to the place represented on URL else default place
historyHandler.handleCurrentHistory();
}
ニースたとえば、私が後だっただけで何。私はあなたが場所を使うために活動を使う必要がないと信じさせたネット上のいくつかの記事を読んだ。 ExampleViewImplとExampleActivityはすき間にうまく埋められました。あなたの例は、Googleの記事にうまく組み込まれています。返信を投稿する時間をとっていただきありがとうございます、大変感謝しています。 – K2J