Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Offline capabilities with local storage
Offline capabilities with local storage [message #886550] Fri, 15 June 2012 06:55 Go to next message
Norbert Winkler is currently offline Norbert Winkler
Messages: 3
Registered: June 2012
Junior Member
Hello,
in my company we currently evaluate RAP (among other technologies) for our next project.
One problem we see with RAP, is that if you have larger input forms
and somehow the server breaks or the connection is temporarily lost during typing,
the whole input will be lost when you try to save it.

I tried to deal with the problem with the help of client listeners
(from the clientscripting project) and local storage.
I managed to save all the input to the local storage while typing
and added a button which reloads the values from the storage and puts it back into
the fields.

The problem is, that if I write back the values to the input fields with JavaScript,
no events will be fired and RAPs model won't be updated. Therefore when I try
to save the input on the server after the data recovery, the textfields don't contain
any text. I would have to manually go to each input field and add and delete a character,
so that the model gets updated, which of course isn't really a solution.

Now I know that with clientscripting you shouldn't really access the DOM elements.
I still would like to try it anyway.
Does anyone know what I could do to achieve my goal?
Maybe there's also another approach that I just haven't seen by now.

Regards,
Norbert

[Updated on: Fri, 15 June 2012 07:09]

Report message to a moderator

Re: Offline capabilities with local storage [message #886600 is a reply to message #886550] Fri, 15 June 2012 08:59 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim Buschtoens
Messages: 386
Registered: July 2009
Senior Member
Hi!

> the whole input will be lost when you try to save it.

Hm, it should not get lost immediately. There should be a message that
the connection failed, and lets you retry. Of course, you can abort or
cause a new session with that, so it's still a valid problem. Just
asking if you get that message.

Using clientscripting is a cool idea, may i ask how you managed to do
this in detail?

> The problem is, that if I write back the values to the input fields with
> JavaScript,
> no events will be fired and RAPs model won't be updated.

SWT does not fire events on setText, but the model should be updated
anyway with the next request. On some properties this does not work yet,
but it should work on text. If not, please file a repoert on bugzilla
and we will fix it asap. However, if this requires changes to the RAP
core (i don't know yet), you will have to move to a nightly build or the
next milestone get get the changes.

> Now I know that with clientscripting you shouldn't really access the DOM
> elements.

You also cant. The widgets internals are pretty well encapsulated, you
probably won't get to the element.

> Maybe there's also another approach that I just haven't seen by now.

We may introduce an easy way to send data from client to server by
clientscripting in the coming months, but nothings sure yet. Other than
that, i think you found the best solution for the current state of RAP.

We thought about introducing RAP offline features a few times, but it's
hard to find a good solution and the time to do it, and demand wasn't
very strong.

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Offline capabilities with local storage [message #886648 is a reply to message #886600] Fri, 15 June 2012 11:07 Go to previous messageGo to next message
Norbert Winkler is currently offline Norbert Winkler
Messages: 3
Registered: June 2012
Junior Member
Thanks for your response!

> Hm, it should not get lost immediately. There should be a message that
> the connection failed, and lets you retry.

I do get the message, but as you said it's still a problem, because
everything you typed is lost when a new session is created.

> Using clientscripting is a cool idea, may i ask how you managed to do
> this in detail?

Well I basically add client listeners to all my input fields with
clientListener.addTo(someTextField, SWT.Modify);
which contain a JavaScript function for saving the input to the local storage like
function handleEvent( event ) {
localStorage['0'] = event.widget.getText();
}

I enumerate the storage entries so that I can iterate through the entries
at recovery.
For recovery I add a client listener to a button which loads the data from the local storage.
I currently take the first value from the local storage and put it
in the first input field on the page, the second in the second and so on.
This is where I directly access the DOM elements.
I hope to do this in a nicer way in the future, but currently I can not
make a mapping between storage entries and input fields as the input fields
don't have an id.
I read that data, set with the setData - method,
should be synchronized between client and server in future versions, which would enable a nice mapping.
As I said I'm not happy with this solution but for now it works.

Edit:
A client listener which is fired after rendering (when the page is fully loaded) would be a great feature.
When attached to an input field, each field could retrieve its own value
from the store.

The problem is, that when I write back the values from the local storage
to the input field with JavaScript this data is not synchronized with the server.
Therefore when I try to retrieve the values with someTextField.getText()
on the server I get an empty String.

So what I would like to do is write back the values
and then trigger a resync of all input fields with the server.

[Updated on: Fri, 15 June 2012 11:40]

Report message to a moderator

Re: Offline capabilities with local storage [message #886672 is a reply to message #886648] Fri, 15 June 2012 12:02 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim Buschtoens
Messages: 386
Registered: July 2009
Senior Member
Hi!

> Well I basically add client listeners to all my input fields with
> clientListener.addTo(someTextField, SWT.Modify);
> which contain a JavaScript function for saving the input to the local
> storage like
> function handleEvent( event ) {
> localStorage['0'] = event.widget.getText();
> }

So you have a different listener for each field? Or how do you know
where to put each value?

> For recovery I add a client listener to a button which loads the data
> from the local storage.
> I currently take the first value from the local storage and put it
> in the first input field on the page, the second in the second and so on.
> This is where I directly access the DOM elements.

Ah so you do create a list of all html input-elements and access them
that way?

> I hope to do this in a nicer way in the future, but currently I can not
> make a mapping between storage entries and input fields as the input fields
> don't have an id.

There is actually a way to assing html-ids in RAP, but its not a really
nice solution either, as you should not access the dom.

> I read that data, set with the setData - method,
> should be synchronized between client and server in future versions,
> which would enable a nice mapping.

I want to point you to an experimental branch of clientscriting that
might help you, but be aware that this API is *NOT* stable. The official
version is the one in the incubator and might implement this feature
differently:

https://github.com/eclipsesource/rap-clientscripting/tree/experimental

Here you can give a map to a listener (the one on your button) where you
can point to other widgets. That could take of the mapping at least when
restoring the values.

> As I said I'm not happy with this solution but for now it works.
>
> The problem is, that when I write back the values from the local storage
> to the input field with JavaScript this data is not synchronized with
> the server.

So you do write it on the html-element, not the widget with setText?
Because setText should work, or if it doesnt its a bug we will fix.

> So what I would like to do is write back the values and then trigger a
> resync of all input fields with the server.
> with the server.

If it all works correctly the valus should be synces with the next
request (as mentioned above).

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Offline capabilities with local storage [message #886677 is a reply to message #886672] Fri, 15 June 2012 12:20 Go to previous messageGo to next message
Norbert Winkler is currently offline Norbert Winkler
Messages: 3
Registered: June 2012
Junior Member
Thank you for your help!

> So you have a different listener for each field? Or how do you know
> where to put each value?

> Ah so you do create a list of all html input-elements and access them
> that way?

> So you do write it on the html-element, not the widget with setText?
> Because setText should work, or if it doesnt its a bug we will fix.

Yes to all.
And you see what the problem is. In the clientlistener of the button
I cannot access the other widgets, only the button itself.

> Here you can give a map to a listener (the one on your button) where you
> can point to other widgets.

This should do the trick. I will have a look at it.
It would be great if this feature could be added to a later (stable)
release of the clientscripting project.

Thank you, I really appreciate your help.

Greetings,
Norbert
Re: Offline capabilities with local storage [message #886687 is a reply to message #886677] Fri, 15 June 2012 12:48 Go to previous message
Tim Buschtoens is currently offline Tim Buschtoens
Messages: 386
Registered: July 2009
Senior Member
Hi.

>> So you have a different listener for each field? Or how do you know
>> where to put each value?
>
>> Ah so you do create a list of all html input-elements and access them
>> that way?
>
>> So you do write it on the html-element, not the widget with setText?
>> Because setText should work, or if it doesnt its a bug we will fix.
>
> Yes to all.

All that stuff should (in the future) not be necessary. We will
definitely add *something* for such situations.

> It would be great if this feature could be added to a later (stable)
> release of the clientscripting project.

Well, let us know if the API works for you (possible bugs aside), every
opinion counts. Something like this *will* be implemented.

>
> Thank you, I really appreciate your help.

Alway nice to see what solutions people come up with. Once this works in
a solid way, i think this would be a cool demo/example to add to the
clientscripting project.

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:How to read a external file after deployment?
Next Topic:Probably simple -- need to add links to page
Goto Forum:
  


Current Time: Sun Oct 26 09:43:20 GMT 2014

Powered by FUDForum. Page generated in 0.01768 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software