Mojo Lists: Using a Cookie as a Data Source (Part 2)
In Part 1 of this tutorial we created the base for our application. It consisted of a static list that was displayed when the application was launched.
At the end of Part 1 you were able to build the application and tap on any of the items which would push another scene. In Part 2 of this tutorial we are going to focus on using a cookie as a data source for our list. We will build a list that will display a list based on a cookie's contents.
When you tap on a list item you will be taken to another scene where you will be able to change the title for the list item and it will be retained in a cookie. I did find an issue with cookies on the emulator and device. There is a known bug that cookies will retain on the emulator and device even after the application is removed. To learn more about this issue and cookies I suggest you read the Working with Cookies tutorial.
We will be continuing with the code that we created in Part 1 so open that application up. We will first be creating a model object that we will use to interact with the Mojo cookie stuff. In your application create the folder /app/lib/ and then create a new file named WBCookie.js and put it in your newly created lib folder. Now you will also have to update your sources.json so that Mojo will know where to find this file. Be sure that your sources.json file looks like the code below.
[
{ "source": "app\/lib\/WBCookie.js" },
{"source": "app\/assistants\/stage-assistant.js"},
{
"source": "app\/assistants\/main-assistant.js",
"scenes": "main"
},
{
"source": "app\/assistants\/cookie-assistant.js",
"scenes": "cookie"
},
{
"source": "app\/assistants\/depot-assistant.js",
"scenes": "depot"
},
{
"source": "app\/assistants\/sqlite-assistant.js",
"scenes": "sqlite"
}
]
Working with Cookies
Over the last few days I have been working with the Cookie as a method for storage on the Palm Pre. I looked in the WebOS Book and there was a nice cookie class that could be used. This will not be a complete walk-through like the last tutorials have been. This will show you how to create a cookie object and how to interact with it so that you can store your application preferences. You can store any type of data you would like in a cookie. It does not seem to be like the Depot where you can *only* store objects.
At the time of writing I have found an issue with using cookies so be sure to read the second to last paragraph.
Below is the class that was taken from the WebOS Book which we will be using for our Cookie object.
Navigation
Calendar
| << | Jun 2010 | >> | ||||
| M | T | W | T | F | S | S |
| 31 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
Most Viewed
- A Basic WebOS Application... (2,983)
- Mojo Lists (Part 1) (1,484)
- Mojo Lists: Using a Cooki... (977)
- Mojo Lists: Using the Dep... (836)
- Mojo Lists: Restructuring... (645)
- Working with Cookies (484)
- Events (213)
- Tutorials (140)
- First Meeting Scheduled f... (82)
- Annoying bug found in Pal... (76)
Categories
- App Catalog (1)
- Bugs (1)
- Development (8)
- JavaScript (2)
- Meetings (8)
- Mojo (5)
- Organization (11)
- Palm (2)
- Tutorials (8)
StatPress
Visits Today: 0Total Visits: 4493
Guests Online: 0
Members Online: 0
Archives
- October 2009 (2)
- September 2009 (10)
- August 2009 (11)