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.

Bug 254080 - Persistent storage for @Model classes
Summary: Persistent storage for @Model classes
Status: RESOLVED WONTFIX
Alias: None
Product: platform
Classification: Unclassified
Component: Html4j (show other bugs)
Version: 8.1
Hardware: PC Linux
: P4 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2015-08-02 18:42 UTC by Jaroslav Tulach
Modified: 2017-02-18 06:39 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Models.storageCtx() to allow persistence (29.14 KB, patch)
2015-08-02 18:42 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2015-08-02 18:42:09 UTC
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.
Comment 1 Jaroslav Tulach 2015-08-02 18:42:45 UTC
Created attachment 155126 [details]
Models.storageCtx() to allow persistence
Comment 2 maxnitribitt 2015-08-15 11:40:47 UTC
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.
Comment 3 Jaroslav Tulach 2015-08-25 14:39:16 UTC
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.
Comment 4 Jaroslav Tulach 2015-08-25 20:15:11 UTC
Slightly too late for 8.1 and HTML/Java 1.2 I am afraid.
Comment 5 Jaroslav Tulach 2017-02-18 06:39:03 UTC
Maybe there is no need to complicate the core HTML/Java API with persistence.