In general, trying to store the application state by storing the widget itself is a bad idea, would be very expensive and of course with no deep clone doesn't even work. Better is to extract just the data needed to reconstruct the widget state and store that, then reconstruct the state on history changes. Depending on your app design you may already have methods to do this, ie to build the initial widget contents or to send them back to the server.
Also as an aside, note that History.newItem() will actually call the history change event, which in this case would immediately try to reconstruct the widget with the data you just captured (or are about to capture). Be sure to add a flag or something so your change handler does not do this unnecessary restore when you are manually adding history items. On May 20, 7:33 am, Mike Jiang <mikej1...@gmail.com> wrote: > I tried to use History class to manage the handling of the back/forward > functioning of the browsers. In order to do that, I need to save the screens > with state to a collection, such as a HashMap, hmap. > For example, the screen is represented by a Composite object, compObject, > which contains a widget object: wgtObject. Every time when I said that the > screen was changed, it implied that the only the wgtObject was changed. When > I used the History to do that, the code is like, > > Hostory.newItem(screenName); > hmap.put(screenName, compObject); > > However, since the compObject is the same instance, on the onValueChange() > > public void onValueChange(ValueChangeEvent<String> event) { > String screenName = event.getValue(); > Composite composite = hmap.get(screenName); > if (compObject != null) { > RootPanel slot = RootPanel.get("mainPanel"); > slot.clear(); > > slot.add(composite); > > } > } > > even the code turned to different screens, the same screen remained > unchanged. The reason is that the compObject rather than wgtObject is saved > to hmap! > > But I need to save compObject with its state to hmap. So I need to clone the > compObject before saving it to hmap. Since there is no Object.clone() > available for GWT, how can I do that? > > Thanks, > > Mike J. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.