4 Replies Latest reply on Sep 12, 2010 10:42 PM by kien_nguyen

    Setting gadget userprefs affects other gadgets on the page

    jkranes

      I have created a simple gadget to experiment with the gadget setprefs feature.  The gadget is based on google's reference implementation.  The gadget is then added to a portal page using the dashboard portlet.

       

      I have noticed that when my gadget updates a user preferences value, all other gadgets on the same portal page are refreshed and lose any state they may have had.  Is this expected behavior?  I would have expected that updating user preferences would be implemented as an ajax request to the server and thus and should affect only the state of the gadget that is making the request.

       

      Is the behavior that I am seeing normal?  Is there some way to set preferences in a way that does not affect other gadgets?

       

      I am using the latest GateIn version (3.1 final with Jboss AS 5.1.0)

       

      Gadget XML:

       

       

      <?xml version="1.0" encoding="UTF-8" ?> 
      <Module>
        <ModulePrefs 
          title="Gadget4">
          <Require feature="opensocial-0.8"/>
          <Require feature="setprefs" /> 
          </ModulePrefs>
        <UserPref 
          name="counter" 
          display_name="counter"
          datatype="hidden"/>
        <Content type="html">
        <![CDATA[ 
          <div id="content_div" style="height: 100px;"></div>
          <script type="text/javascript">
      
          // Get user preferences
          var prefs = new gadgets.Prefs("test");
          var counter = prefs.getInt("counter");
          var div = document.getElementById('content_div');
          div.innerHTML = "The count is " + counter + ".";
          // Increment value of "counter" user preference
          function incrementCounter() {  
            counter++;
            prefs.set("counter", counter);
          }
      
          // Reset value of "counter" userpref to 0
          function resetCounter(){
            prefs.set("counter", 0);
            div.innerHTML = "Count reset to " + prefs.getInt("counter") + ".";
          }
      
          </script>
          <input type=button value="Count" name="count" onClick="incrementCounter()">
          <input type=button value="Reset" name="reset" onClick="resetCounter()">
        ]]> 
        </Content>
      </Module>