Preferences |
This method stores user preferences and information in the XML Store.
Syntax
HTML |
<div cordysType='wcp.library.util.Preferences' id=sId file=sFileName > ... </div> |
where,sIddenotes the unique identifier for the preferences component. If this identifier is not specified for the component, then the component automatically registers itself in the page aswindow.preferences.
The preferences component stores the files in the preferences folder according to their version. Since the content is stored in the XMLStore, preferences maintains three versions of files, which are isv, organization, and user. Preferences that are supplied and are auto-generated by Process Platform Ajax Toolkit are of 'isv' type. If any of such files are modified by a user, it becomes 'user' version. By default, any file created using preferences component becomes a 'user' version. Any developer could be able to set the version for preferences file using theVersionproperty exposed by this component.
User preferences are transient. Their presence in the code cannot be relied.
To dynamically add and initialize this component, you can use theinitializeHTMLElementsoraddTypemethods of the Application object.
The properties and methods exposed by this component are as follows:
Table 1. List of Attributes
Attribute |
Property |
Description |
---|---|---|
file |
file |
Required. String that denotes the key of the XML Object in the XML Store. This value will be preceded by cordys/wcp/desktop/preferences. By default, this will be the ID of the application. |
id |
id |
String that denotes the unique identifier of the preferences component. |
version |
version |
String that denotes the version of the file stored in preferences folder. The following are the possible values:
|
organization |
|
String that specifies the organization for which user preferences must be stored. You can specify the organization as an inline attribute as shown in the following example. <div cordysType="wcp.library.util.Preferences" file='MyPrefernces' id="mypref" organization = ""o=org1,cn=cordys,cn=tapbuild,o=vanenburg.com""> ... </div> |
Table 2. List of Methods
Method |
Description |
---|---|
getProperty(name, defaultValue) |
Retrieves the value of property in the preferences with the specified |
Sets the value of a property in the preferences. |
|
read |
Makes an explicit retrieval of the preferences data from the XML Store. The preferences data for the specific property can be retrieved through thegetProperty()method. |
getData |
Gets the value of the data property. |
setData |
Sets the data property, which is an object that denotes the tuple element received from the back end which contains the preferences data. |
save |
Explicitly saves the data in the preferences to the XML Store. If this method is not called explicitly, the preferences data is automatically stored to the XML Store when the application is closed. |
setOrganization() |
Sets the organization for which to save user preferences. The organization can be set as follows: mypref.setOrganization("o=org2,cn=cordys,cn=tapbuild,o=vanenburg.com") |
Example
The following example shows how this method is used to store data.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html onapplicationready="cordys.setTextContent(document.getElementById('fileName'), myPreferences.getAttribute('file'))" > <head> <title>Preferences</title> <script type="text/javascript" src="/cordys/wcp/application.js" ></script> <script type="text/javascript" > function putXML() { var xmlObject = cordys.loadXMLDocument(document.getElementById("xmlContent").value); if (xmlObject) { myPreferences.putProperty('myXML', xmlObject.documentElement); application.notify('Done'); } } function getXML() { var myXML = myPreferences.getProperty('myXML'); application.notify(myXML ? cordys.getXML(myXML) : "No Preferences XML"); } function putText() { myPreferences.putProperty('myText', document.getElementById("textContent").value); application.notify('Done'); } function getText() { application.notify(myPreferences.getProperty('myText')); } </script> </head> <body> <div cordysType="wcp.library.util.Preferences" id="myPreferences" file='cordys/wcp/myFolder' style="display:none;" ></div> <h4>preferences Demo page</h4> File : <label id='fileName' style='width:260px'></label> <br> <br> XML : <br> <textarea id='xmlContent' style='width:300px;height:200px'></textarea> <button class='medium' onclick='putXML()'>PUT</button> <button class='medium' onclick='getXML()'>GET</button> <br><br> Text : <br> <input type='text' id='textContent' style='width:300px'> <button class='medium' onclick='putText()'>PUT</button> <button class='medium' onclick='getText()'>GET</button> <br><br> <button id='read' class='medium' onclick='myPreferences.read()'>Read</button> <button id='save' class='medium' onclick='myPreferences.save()'>Save</button> </body> </html>