Building Mobile Enterprise Applications : webMethods Mobile Development Help : Code Snippets : Using the Context Key Store to Store and Retrieve Application-wide Settings
Using the Context Key Store to Store and Retrieve Application-wide Settings
Mobile Development follows the Model-View-Controller architecture which splits user-written business logic from the generated sources. A frequently-asked question is how to take over a set of data from one view into another. The ContextKeyStore offers a simple way to achieve this goal from the application model and also programmatically.
When you use the application model, the input fields (Entry and SearchEntry) populate the property Context Key, which requires a String value as a unique name. Setting up Entry or SearchEntry elements with a context key will generate a logic which automatically saves the entered value to the ContextKeyStore. To identify the data, the specified context key is taken into account as a unique key. In addition to storing the data, any already contained value will be automatically applied to the UI element. All entered context keys will be generated to the ContextKeys.java interface. The context key can be embedded in any text property using the {@CONTEXT_myContextKey} syntax. This token will be automatically resolved and replaced with the actual value.
Using a programmatic approach, you need to put a key value pair into the ContextKeyStore, as described by the following snippet:
import com.softwareag.mobile.runtime.toolkit.util.ContextKeyStore;

ContextKeyStore.set("MyKey", "MyValue");
String myValue = (String) ContextKeyStore.get("MyKey");
Supported values are all primitive types including String. To store a date value, you need to put the corresponding long value into the ContextKeyStore, using the java.lang wrapper classes for primitive types:
final Date date = new Date();
final long dateAsLong = myDataObject.getTime();
ContextKeyStore.set("MyDate", new Long(dateAsLong));
The values contained in the ContextKeyStore can be persisted. For this, the application property Context Persistence Mode must be set to Permanent. All values and their keys are then placed in a RecordStore when you close the application. They are automatically loaded when you start the application again.
Copyright © 2007-2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback