2

Using GWT with the MVP pattern, I'd like to have a place that represents a somewhat more complex state (as opposed to the canonical example that has only a "name"). My first inclination was to use a shared transfer object that I would serialize for the token. However, Gson (the serialization library I'm using), does not appear to be GWT compatible.

I started down the path of manually serializing and deserializing myself, but this seemed like a use case that must be fairly common. So my question is: what is the "ordinary" means of tokenizing a the complex state of a place?

Ray
  • 4,829
  • 4
  • 28
  • 55
  • Hi, how complex is your place? If it's just the id of the subject record you can use "user:12" to append the id to the place token. Multiple fields can be added using a delimiter of your choosing. – ianmayo Jun 15 '11 at 11:04
  • I have a couple of use-cases. One is "search criteria", where we could have multiple criteria, and each criterion has several fields (e.g., "field to filter on", "filter type", "value") – Ray Jun 15 '11 at 11:31
  • In that case I support Peter's answer below. If your tokens can fit into a couple of hundred characters just use a Tokenizer as at http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html If more, you'll have to store the query in your database and refer to it via an id. – ianmayo Jun 15 '11 at 13:18

2 Answers2

1

History tokens are part of URL and show up in the browser address bar. To make this work you'd first need to serialize them, then URL encode them. Also there are practical limits to how long the URL can be: What is the maximum length of a URL in different browsers?

Do you plan to bookmark this URL? If not, you should just store the object in a map under some ID and include this id in a token.

If you do need to go down your route then generating JSON in GWT is most easily done via Overlay Types.

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
0

We had this problem too.

What we did was to use the object ID in the place and store the object at the server, this makes the URL more friendly, the drawback is the extra call to the server to recover the object.

Another advantage of this solution is that you keep control over the object, you can update it at any moment.

LuisKarlos
  • 527
  • 6
  • 6