This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Applications based on HTML/Java API often need to deal with persisting its local state. This request is to design an API that would allow persistence of @Model generated classes.
Created attachment 155126 [details] Models.storageCtx() to allow persistence
if I understand correctly I need at least two Models if I want to persist the data. The first one (Persistence in your example) defines the properties that will be persisted. The second one (UI) exposes these Properties via ComputedProperties and delegates to Peristence. That’s very verbose. From the perspective of a user of the API I would prefer to be able to define my model as before and simply ask the system to persist it whenever something changes: @Model(className = "UI", targetId="", properties = { @Property(name = "name", type = String.class } ) final class UICntrl{ static void</b> onPageLoad() throws Exception { UI ui = PersistenceManager.getDefault().registerForAutoPersist("id", UI.class); ui.applyBindings(); } } Then depending on the Technology the PersistenceManager has to track changes in any of the properties and persist the data on change. registerForAutoPersist would first check if there is already persisted data and pass back either that or new Instance. Then it would register for changes in any of the properties and automatically persist whenever there's a change. With knockout this should be possible by walking the Observables and tracking like here (maybe there are more elegant ways): http://jsfiddle.net/KeesCBakker/22XPF/ For other technologies we would have to provide different implementations. Also I would like to be able to persist data in a more controlled way. In this example: https://dukescript.com/dukescript/2015/01/01/Persisting-State-with-DukeScript.html Here we can control when data is persisted. E.g. when the user presses a button to save game state. So there are two use cases: explicitly save and autopersist. If I understand correctly this example only supports autopersist.
In case one wants to access all properties of the object stored in the storageCtx() one can do: @ComputedProperty static Persist visible(Persist persist) { return persist == null ? null : persist.clone(); } and use <div data-bind="with: visible"> <-- access all the properties --> </div> It shouldn't be that verbose. But if it is, and as there is no other implementation ready that would require changes into the net.java.html.json API, we can drop this API change for the time being.
Slightly too late for 8.1 and HTML/Java 1.2 I am afraid.
Maybe there is no need to complicate the core HTML/Java API with persistence.