Pixelbox

Welcome to Pixelbox. Friday the 10 of October 2008

Skip to content >>

Saving data from Dashbaord Widgets

A while ago I created a dashboard widget to help people accessing the admin side of Ceros. It saves a lot of time with remember user credentials, and acts as a master key for accessing restricted areas.

One thing that was causing a bit of a problem was saving preferences (passwords) when the users restarted their machine, or logged out. This caused the user to re-enter their password every time, making it a lot less useful.

I tried searching Google for ways to save data from dashboard widgets, write data to a dashboard widget database, store data in dashboard widgets etc with no joy. I flirted with the idea of writing to a database on a web server, although this seemed a bit of an overkill for a few settings.

Eventually I discovered that you can set preferences via the widget class, which the dashboard framework then saves for you (probably in an unsecured way) for access at a later point.

Essentially you use the function:


widget.setPreferenceForKey("Goodbye, World!","worldString");
And then get the data back like so:

var worldString = widget.preferenceForKey("worldString");

More info on saving preferences can be found here.

Meta tags: Random

There are no comments yet

Add your own comment