Question

I am trying to save a persistent variable for iWidget instances in IBM Connections 4.0

Documentation (link & link) leads me to the following javascript (run with the iWidget in Edit mode):

this.iContext.getiWidgetAttributes().setItemValue("instance","helloWorld");
this.iContext.getiWidgetAttributes().save();  //or .commit(); as save is deprecated

I also tried defined the variable in the widget XML definition:

<iw:itemSet id="attributes" private="false" onItemSetChanged="itemSetChanged">
    <iw:item id="instance" value="" readOnly="false"/>
</iw:itemSet>

This sets the value correctly in the local instance, I also see a PUT request to the server to save this value. It returns a 404 Response code. The URL is:

/connections/opensocial/common/repos?st=default%3AcQitETUij2Iqg0A_8mB9A35-pRKmnH_dFUgT4rY-hERIC3ZTNW3hp0OeLr_SYZ2mXWW6OjMtcFPijI_YaIaCDZlduzYgn5FkYQUTiqngHgLqsBMG&type=itemSet&pageId=undefined&widgetId=widget_d785df84b58d4d459707a048014567f6_1369275060798&itemSetId=attributes

The value is no longer stored when I reload the page and try to retrieve it again using:

this.iContext.getiWidgetAttributes().getItemValue("instance");

I notice there is a "pageId=undefined" in the URL. There are no outputs in the SystemOut.log of the Connections servers.

At the moment this is running in the Homepage "My Widgets" page, but will also be run in Communities application later.

Thanks

Was it helpful?

Solution

For anyone else that comes across this problem, here is what I found;

It turns out that saving through the Homepage refused to work, however I did successfully save Instance Data when the widget is loaded through the Communities mechanism;

JavaScript for saving (.save calls a callback function, but not necessary):

if(this.inCommunity)
{
    this.iContext.getiWidgetAttributes().setItemValue("instance",contentToSave);
    this.iContext.getiWidgetAttributes().save(dojo.hitch(this,this.dashboardSaved));
}

Loading saved data:

this.instanceData = this.iContext.getiWidgetAttributes().getItemValue("instance");

Widget definition (in widgets-config.xml)

<widgetDef defId="Dashboard" description="MyDash" modes="view edit" url="/Dashboard.xml" uniqueInstance="false">
    <itemSet>
        <item name="instance" value=""/>
    </itemSet>
</widgetDef>

Dashboard.xml

<iw:iwidget xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget" iScope="Dashboard" supportedModes="view edit" mode="view" allowInstanceContent="true">
    <iw:resource uri="./dashboard.js"/>
    <iw:event id="view" handled="false" onEvent="onView"/>
    <iw:event id="edit" handled="false" onEvent="onEdit"/>
    <iw:event id="onRefreshNeeded" handled="true" onEvent="onRefresh"/>
    <iw:itemSet id="attributes" private="true" onItemSetChanged="itemSetChanged">
        <iw:item id="instance" readOnly="false"/>
    </iw:itemSet>
    <iw:content mode="view">
        <![CDATA[<div id="RootWidget"></div>]]>
    </iw:content>
    <iw:content mode="edit">
        <![CDATA[<div id="RootWidget"></div>]]>
    </iw:content>
</iw:iwidget>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top