Symbian
Symbian OS Library

FAQ-0732 Why do ContactTemplates recovered from a ContactDatabase have all field values except the formatted name stripped out?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: JavaPhone
Created: 08/23/2001 Modified: 09/11/2002
Number: FAQ-0732
Platform: Symbian OS v6.0, Symbian OS v6.1, Symbian OS v7.0

Question:
When I save a ContactTemplate in my ContactDatabase then recover it again, I find all the field values except the formatted name have been stripped out. This appears to be a defect against the JavaPhone 1.0 spec which states that a "template contact item defines a set of default fields (possibly with default values)". Is it not possible on Symbian OS to save field values on a ContactTemplate?

Answer:
Technically this is a defect against the JavaPhone 1.0 spec. The problem stems from a mismatch between the JavaPhone concept of a contact template and Symbian OS's native concept. The latter is concerned with what the user sees displayed when they select "New contact" in the native Contacts application. Normally this will be based on what is termed the "golden template" which defines a standard set of fields including, e.g., home and work telephone numbers and addresses. Unlike in JavaPhone templates, these fields will typically all be empty for the user to type data into. (If the user wishes to define other fields these can typically be added too.) So when a new ContactTemplate is added to the ContactDatabase from JavaPhone with the addItem(Item) method of javax.pim.database.Database, the native method which gets invoked to do this keeps all the fields, but deletes all their data, with the exception of the formatted name, which is typically needed to allow the template to be recovered later.

    However there is a convenient work around for this problem because the updateItem(Item) of javax.pim.database.Database does not distinguish between templates and cards but saves both with all their fields intact. You can therefore save a template with all its fields as follows:

    try {
    ContactDatabase db = ContactDatabase.openDatabase()
    } catch(DatabaseException dbe){...}
    ...
    ContactTemplate template = new ContactTemplate();
    template.setFormattedName("Symbian");
    ItemField url = new ItemField(ContactDatabase.URL, "www.symbian.com");
    template.addField(url);
    ...
    try {
    Item copy_of_template = db.addItem(template); // saves the fields without their data and returns a reference
    // to the copy of the template in the database

    db.updateItem(copy_of_template ); // adds in the data too
    ...
    db.close();
    } catch(DatabaseException dbe){...}