On Sep 21, 10:47 am, sasajovancic <
sasajovan...@hotmail.com> wrote:
> I think place service is good proposal.
>
> I have one concern how some big event objects like Widgets are going
> to be stored in string. Or they should be converted to db or some
> cache file system.
I don't think you will store widgets but more beans that contain
information needed to retrieve the same state you were at.
You are free to store the bean the way you want.
For example with the following bean:
public class UserBean{
String lastName;
String firstName;
int id;
....
}
You could decide to store all the information in the URL:
myurl#myAction?lastName=...&firstName=...&id=...
so you could have the following History Adapter:
public MyHistoryAdapter(){
...
public String convertToToken(UserBean user){
return "lastName=" + user.getLastName() + "&firstName=" +
user.getFirstName() + "&id=" + user.getId();
}
public void convertFromToken(String event, String token, EventBus
eventBus){
String[] attributes = token.split('&'');
UserBean user =new UserBean();
user.setLastName(attributes[0].split('=')[1])
...
eventBus.dispatch(event, user);
}
}
You could also decide to store in the URL only a part of your bean
(for example the key to identify it) and retrieve the rest of the
information from the server:
myurl#myAction?id=...
You will have then the following History adapter:
public MyHistoryAdapter(){
...
public String convertToToken(UserBean user){
return "id=" + user.getId();
}
public void convertFromToken(String event, String token, EventBus
eventBus){
UserBean user =new UserBean();
user.setId(attributes[0].split('=')[1])
services.retrieveUserInformation(user, new AsyncCallback<UserBean>
() {
public void onFailure( Throwable caught ) {
//do sthg
}
public void onSuccess( UserBean user ) {
eventBus.dispatch(event, user);
}
}
}
I actually just noticed that History Adapter functions don't manage
asynchronious called. Maybe I will add the event bus as an attribute
of convertFromToken function(as I did above) but I will have to think
about it.
>
> What will happen if widget state is changed (state of widget, view
> changed in meantime) before we go back?
I think when you deal with history, there are at least 3 cases to
manage when history is fired:
-You can retrieve needed information for the action and the state of
your application (ie your widgets) allows you to execute it
=> in this case, you can just fire the event to the event bus.
-You can retrieve needed information for the action but the state of
your application don't allow you to execute your action (for example
extra information is needed because information that were present when
you stored your token is not present anymore)
=> in this case, you need to fire an event different from the one you
stored but with the same information to tell your application that you
try to execute the stored event but it needs to do something else
first).
-You can't retrieve information (for example session is expired)
=> in this case, you send an event with no information in order your
application to display an error message.
The framework won't be able to automaticaly manage these cases. It
will be the developer job to tell the framework what event to send by
coding the convertFromToken function.
For example:
public void convertFromToken(String myEvent, String token, EventBus
eventBus){
UserBean user =new UserBean();
user.setId(attributes[0].split('=')[1])
services.retrieveUserInformation(user, new AsyncCallback<UserBean>
() {
public void onFailure( Throwable caught ) {
// information can't be retrieve, send an error message
eventBus.dispatch(myEventError)
}
public void onSuccess( UserBean user ) {
if (stateApplicationOk){
//state of the application and information ok
eventBus.dispatch(event, user);
}
else{
//state of the application ko
eventBus.dispatch(otherEvent, user);
}
}
}