2014-06-12

Accessing a portal page metadata using Javascript.

The WebSphere Portal has got a client based interface towards many of it's functions, this interface is called the mashup client interface and comes from the mashup server product which has been incorporated into the WebSphere Portal product.

Here is a small example of how to read the pagemetaData parameters from a page using javascript:
        var nm = com.ibm.mashups.enabler.navigation.Factory.getNavigationModel();
        var selectedNode = nm.find(ibmCfg.portalConfig.currentPageOID).start();
        // fetch the currentpage metadata only
       selectedNode.getmetaData("metdataparametername");
       // fetch all aggregated metadata values
        metadatavalue = aggregatedPageMetadata["metadataparameter"];
Here is an example of how to store new metadata values:

    var nm = com.ibm.mashups.enabler.navigation.Factory.getNavigationModel();
    var selectedNode = nm.find(ibmCfg.portalConfig.currentPageOID).start();
    selectedNode.setMetaData("cds.css." + type ,url);    
    nm.commit().start(); // Sync save.
var asyncSave = nm.commit(); 
asyncSave.setFinishedCallback(commited);
asyncSave.setOperationCallback(commitoper);
asyncSave.start();

// finished callback function
function commited(result, status) {
    // handle overall status
    if (status == 200  status == 201) {
        alert("Successfully committed navigation model.");
    } else {
        alert("Failed to commit navigation model;
HTTP status code '" + status + "'.");
    }
}
// operation callback function
function commitoper(result, operation, status) {
 if (operation == asyncSave.OPERATION_SAVE){
}else if (operation == asyncSave.OPERATION_MODIFY){
}else if (operation == asyncSave.OPERATION_DELETE){
}

}