×

Discussion Board

Results 1 to 10 of 10

Hybrid View

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    20

    Unhappy PRoblem persisting data

    Greettins.
    I am trying to persist some data that i get in the web page using an xhr request.
    The problem it's seems to be that no data is being recorded to the phone as in the next launch you can not retrieve the info.
    • I am using the "Nokia Web Developer Environment 1.2.0" currently to developt the app and testing with the preview emulator that comes within.
    • Using the widget.preferences.setItem(key,data) and widget.preferences.setItem(data) as the doc says

    I paste the javascript along with html code to see what i am doing more precisely


    HTML CODE:
    Code:
     	<input type="button" onclick="getJSON();" value="Get JSON"/><br/>
    	<input type="button" onclick="getIt();" value="retrieve data from pref"/>
    JAVASCRIPT CODE:

    Code:
    function getJSON()
    {
    	var xhr;
    	xhr = new XMLHttpRequest();
    	xhr.open("GET","http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US", true);
    	xhr.onreadystatechange = function(){
    		if (xhr.readyState == 4) {
    			if (xhr.status == 200) {
    				document.getElementById('test').innerHTML= "<b>"+ xhr.responseText + "</b><br/>";;
    				widget.preferences.setItem("REG001",xhr.responseText);
    			}
    			else {
    				document.getElementById('test').innerHTML= "Error code " + xhr.status;
    			}
    		}
    	}
        xhr.send(null);
    }
    
    function getIt ()
    {
    	document.getElementById('test').innerHTML = document.getElementById('test').innerHTML + "<br/>" + widget.preferences.getItem("REG001");
    }
    Well thanks for advance.
    Grettins!.
    Víc

    P.D: This wasn't actually tested on a real phone, just on the emulator. BUT it obviously must work, or don't?
    Last edited by VituchoInfonor; 2011-08-09 at 02:19. Reason: Additonal info added

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    20

    Re: PRoblem persisting data

    I go further and discover that even the examples found in "http://www.w3.org/TR/widgets-apis/#storage-area" named "6.4.3. Usage Example 1" and "6.4.4. Usage Example 2" aren't working.
    I know myself and a recognize my lack of abilities but for sure i bet i know how to do copy and paste.. and that is not working neither....
    Please someone help me!.
    Greetins!!

  3. #3
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Posts
    115

    Re: PRoblem persisting data

    Hi,

    We have identified some inconsistencies with widget preference behavior.

    What you can try is make sure you have the preferences you're planning to save pre-defined in config.xml before using then to store data. (See code below)

    We're working to fix the remaining issues in this area.

    petro

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
     <widget xmlns="http://www.w3.org/ns/widgets" height="200" id="http://preftest" version="1.0.0" viewmodes="windowed fullscreen" width="200">
    ...
    
        <preference name     = "UserID" 
                  value    = "-1"
                  readonly = "false" />
        <license>
    	   Copyright Foo Bar Corp, 2011.
        </license>
        
       	<feature name="nokia://s40.nokia.com/SAWRT/1.0" required="true" />
    </widget>
    'petro
    @petrosoininen

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    20

    Re: PRoblem persisting data

    Thanks Petrosoi!
    So keep me up to date with this matter if it's no much to ask!
    Greetings.
    Víctor

  5. #5
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Re: PRoblem persisting data

    Hi, this problem still exists, even with Browser 1.5... really annoying. It works if I use widget.preferences['key']=value, but this way is not in the documentation...
    Last edited by lorion84; 2011-12-11 at 21:07.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: PRoblem persisting data

    Hi,

    This issue regarding setting the preference values also caused me a lot of grief. In fact I still do not know if it will work as expected. Could someone who knows how it is meant to work and what scenarios it can be used for test and document widget.preferences as a wiki page please.

    From my limited testing: if you store a value in the widget.preferences storage and then kill the Nokia Browser: that value will be retrievable if the web app starts again before the default session timeout elapses. If the web app starts after the normal session timeout duration or if the web app times out due to non-use while it is open on the phone then the widget.preferences store will have expired and all values will be lost.

    Personally I would like to be able to store the data for my app on the client device in the Nokia Browser through some kind of mwl Javascript call. Being able to persist some cached data is extremely useful and important. It does not need to be much data as I only need about 2KB to 5KB of cached data to be stored.

    Regards,
    Stephen
    Last edited by sperelson; 2012-01-25 at 00:23. Reason: Altered Perceptions

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: PRoblem persisting data

    Hi Stephen,

    I have sent query to RnD about this issue. I’ll let you know as soon as I know something more.

    PS.
    I would like to thank you about all the feedback you have given here it the discussion board. It is very valuable to us.

    Br,
    Ilkka

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    23

    Re: PRoblem persisting data

    Hi Ilkka,

    Do we have any update on this issue and better if a complete example can be provided. I searched but there is lot of confusion somewhere said use getItem/setItem whereas somewhere it is mentioned to use widget.preferences['user'] etc .. also seen http://www.w3.org/TR/widgets-apis/#storage-area but still not clear what to use.

    Kindly suggest

  9. #9
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: Problem persisting data

    So after a lot of experimenting I now know that widget.preferences is a tricky subject to master.

    I did not understand the reasoning behind the preferences values in the config.xml file that Petro suggested until another Nokia developer pointed me in the right direction. I had previously seen that stored preferences disappear after the web app's session dies. The declared preferences in the config.xml causes these values to persist!

    After hitting my head trying to get this all to work well for my web app: here are my points to remember:
    1. Declare the preferences in the config.xml file:
      Code:
      <widget xmlns="http://www.w3.org/ns/widgets" height="200" id="..." version="1.0.0" viewmodes="windowed fullscreen" width="200">
      ...
      <preference name="clientid" value="" />	
      <preference name="value2" value="" />
      ...
    2. Declare as many as you need - if there is a limit I have not found it yet. I declared 42 in my web app with no obvious issues. I needed this many because...
    3. String values cannot be too long. 256 characters is too long and the value will disappear without warning. I settled on 128 characters for a string value. So to store longer strings...
    4. Break longer strings up among multiple preferences and manage the storage and retrieval in your Javascript. This seems a little wrong, but I do not want to manage this particular small amount of data on my server for each user . In my case, the string is a json string of around 1kb returned from a custom back-end service.
    5. Set a preference with:
      Code:
      widget.preferences['key'] = value;
    6. Read a preference with:
      Code:
      var variable = widget.preferences['key'];

    Follow these steps and your web app will be able to retain important information between instances and sessions. Remembering things such as the last viewed news items or which categories were selected last makes a huge difference for a user and makes your application far more useful .

    I did have an issue with double quotes causing issues when reading them out of the storage. I resolved this by replacing all double quote characters with a pipe character before storage and changing them back when reading the value. This worked for me for my particular data and I did not stick around long enough on this problem to figure out why it was an issue to begin with.

    Regards,
    Stephen

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    23

    Re: Problem persisting data

    Thanks a ton Stephen

    This will be really helpful

    Regards,
    Abhishek

Similar Threads

  1. Replies: 1
    Last Post: 2010-02-23, 14:16
  2. Problem with persisting data into the rms
    By ionutdavid_eu in forum Mobile Java General
    Replies: 2
    Last Post: 2008-01-11, 08:03
  3. Problem with persisting data into the rms
    By ionutdavid_eu in forum Mobile Java General
    Replies: 3
    Last Post: 2008-01-10, 13:15
  4. Problem with persisting data into the RecordStore
    By ionutdavid_eu in forum Mobile Java General
    Replies: 1
    Last Post: 2007-12-19, 12:34
  5. Persisting object trees to RMS
    By jose.moreira in forum Mobile Java General
    Replies: 1
    Last Post: 2006-08-08, 02:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×