How to preserve session state with a canvas?

39 views
Skip to first unread message

membersound

unread,
Jan 7, 2013, 9:57:27 AM1/7/13
to google-we...@googlegroups.com
Hi,

I'm creating a canvas where the user can draw some elements himself.

Is it possible with GWT to preserve the user session somehow? And if he refreshes the browser, all his drawings should be still there / beeing recreated?
Coming from JSF I'd just use @SessionScoped, but how can this be done gwt, if ever?

Thanks

RyanZA

unread,
Jan 8, 2013, 9:46:39 AM1/8/13
to google-we...@googlegroups.com
First you need to get the data from the canvas so you can save that. Use this method:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.2/com/google/gwt/canvas/client/Canvas.html#toDataUrl%28%29

Now for session you have 2 options:

1) You can transmit this data to your server in an http call, and then save that into a database or file - cookie will not work, as the image data will be too large for a cookie.
2) You can save the data in HTML5 local storage: https://developers.google.com/web-toolkit/doc/latest/DevGuideHtml5Storage

Kody

unread,
Jan 8, 2013, 2:13:53 PM1/8/13
to google-we...@googlegroups.com
Thanks I think local store will fit best here.
Reply all
Reply to author
Forward
0 new messages