4 Replies Latest reply on Sep 14, 2005 7:14 PM by Sandeep Pujar

    how to set Preferences

    Sandeep Pujar Newbie

      Hello,

      What is the best way to set preferences in portlets. Is there some document I can refer to.
      I have setup mysql database as the data source to store the preferences.

      I am looking to store prefernces
      1. as some key - value pair.
      2. Per user.

      Other question is can I use PortletPreferences interface from the RenderRequest object ?

      thanks,
      Sandeep

        • 1. Re: how to set Preferences
          Bradley Smith Master

          You can use the PortletPreferences.store() method directly. Behind the scenes, JBoss Portal will save your user preferences (values) in table jbp_user_pref_prop_value (if you want to check with your DB GUI tool).

          In your portlet you should:

          1. obtain a reference to PortletPreferences:

          PortletPreferences portletPrefs = portletRequest.getPreferences();
          


          2. update the desired values of the preferences:

          portletPrefs.setValue(...) or portletPrefs.setValues(...)

          3. Invoke portletPrefs.store().



          • 2. Re: how to set Preferences
            Sandeep Pujar Newbie

            Thanks ,

            I have another question,

            If I have a guest user , then how do I save his preferences ?

            I have it setup and use portletPrefs.store(), but nothing appears in the database, is there any configuration I am missing.

            Below is my code

            PortletPreferences pref = request.getPreferences();
            pref.setValues(team + PREF_METRIC_LIST, metricsArray);
            pref.setValue(team + PREF_ACTIVE_METRIC_LIST, "yes");
            pref.store();


            Thanks for all the inputs,
            Sandeep

            • 3. Re: how to set Preferences
              Viet Master

              could you give a good primary key for a guest user ? if so I can persist it in a database.

              • 4. Re: how to set Preferences
                Sandeep Pujar Newbie

                The primary key can be "guest" .

                I guess PortletPreferences class assumes that there is a current user who
                has logged in.
                For guest this might not work as guest need not log in but still I might want to store some preferences for him.

                Is there a way I can set the user to guest by default and store the preferences for guest ?

                thanks,
                Sandeep