|
PlaceManager
Overview of the PlaceManager
IntroductionThe PlaceManager is the one that will take care of History management. ChoiceYou can disable the PlaceManager if you don't want to use it. But by default it is enabled. To disable it, add in your gwt.xml module: <set-configuration-property name="app.use.place" value="false"></set-configuration-property> PlaceA place is a location in your application. It can be a Presenter or a Controller. The place interface has only one method: void go(D data) {
}Guit PlaceManager implementation needs the places to be Singletons by design. To turn a Presenter or a Controller into a Place you need to:
After doing that your Presenter/Controller will be already a place! ¿Where is my places registration?In Guit you don't need to register the places. Guit scans your gin bindings for classes that implement Place and are binded as Singleton. From that classes Guit build the Places registration. That's what I call zero-configuration! :). StayPlaceA StayPlace is a place with a few extra methods: // When trying to leave the place
String mayLeave();
// When the place is leaved
void leave();
// If mayLeave was called and the user cancelled this method gets called
void stay();I think this is pretty straight. Place nameThe place name that will be used for the token is by default the SimpleSourceName of the presenter. If you want a custom place name, annotate the presenter with @PlaceName("YourCuteNewName") Default placeTo specify your default place, you need to add in your gwt.xml module: <set-configuration-property name="app.default.place" value="com.demo.client.YourPresenter"></set-configuration-property> This place will be called when the history token is empty (in general, when you get into the application). Another situation when it will get called is in production, when the History token gets corrupted. In development mode you will get an assert exception. It is important to note that this is not required. Place dataWhen you declare a place you generally have "data" attached to it. That "data" represents the state of the place. Guit lets you declare that data as a java pojo. @GwtPresenter
public class ComplexPlace extends ComplexPlacePresenter
implements
Place<ComplexPlaceData> {As you can notice, the Place interface takes an argument, that is your place data's type. public class ComplexPlaceData {
private String text;
private boolean enabled;
private String color;
private int textSize = 25;
public ComplexPlaceData() {
}
... getters and setters
}Guit will automatically serialize and deserialize that data for you into the browser's token. Guit had built-in a json orm to do that. Guit json's orm supports any crazy data that you will declare (seriously). But remember: it must be serializable. To get a field serialized:
The following places are also supported: * Place<Void> * Place<Double> * Place<Integer> * Place<String> * Place<Date> * Place<Long> * Place<Enum> GoTo go programmatically to a place you need to call "go()" on the placeManager: placeManager.go(HomePresenter.class, null); NewItemTo programmatically register a new item into the history, call "newItem()" on the placeManager: placeManager.newItem(TablePresenter.class, 2); The newItem method can only be called with the current place as argument. Place hyperlinkAnother way to go to a place is using Hyperlinks. Guit provides two Hyperlinks: PlaceHyperlink and InlinePlaceHyperlink. Same as placeManage.go() and placeManager.newItem() a PlaceHyperlink takes a place class and data. Here is a little tip to use it with uiBinder: @UiField(provided = true)
PlaceHyperlink login = new PlaceHyperlink(LoginPresenter.class);RunAsyncTo code-split a place you need to annotate it with @RunAsync Crypting place token<set-configuration-property name="app.encrypt.place" value="true" /> Otherwise annotate the places you want to encrypt with @PlaceDataEncrypted The default crypter is base64. To use your own you have to turn off the default: <set-configuration-property name="app.encrypt.base64" value="false" /> And bind you crypter in you gin module: bind(Cryper.class).to(JsonToUserlikeCrypter.class); PlaceChangeEventGuit 1.5 introduces PlaceChangeEvent. | |