3 Replies Latest reply on Jul 19, 2006 7:10 PM by peterj

    Unable to persist preferences.

    peterj

      I am trying to update the portlet preferences within my code, but the preferences are not being persisted. I have based my code on what I found in the WeatherPortlet. I even added debugging to the WeatherPortlet to see how it was doing things. Here is the code:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException {
       String newZip = request.getParameter("newzip");
       log.debug("newZip=" + newZip);
       if(null != newZip) {
       PortletPreferences prefs = request.getPreferences();
       try {
       prefs.setValue("RssXml", RSS_URL_PREFIX + newZip);
       prefs.store();
       String xxx = prefs.getValue("RssXml", null);
       log.debug("RssXml=" + xxx);
       } catch(Exception e) {
       e.printStackTrace();
       }
       }
       response.setRenderParameter("newzip", RSS_URL_PREFIX + newZip);
       response.setPortletMode(PortletMode.VIEW);
      }


      And here is what shows up on the log file (sans leading junk):

      newZip=92691
      RssXml=http://xml.weather.yahoo.com/forecastrss?p=33145


      The 33145 zip is what is configured in portal.xml. So immediately after setting the preference and storing it, it disappears and reverts back to the original setting.

      Should I open a JIRA issue?

      Using: JBoss 4.0.4-GA, JBoss Portal 2.4.0-CR1, JDK 5.0

      Standard disclaimer: I searched through the forum, JIRA, and even did a general google and could not find anything on this topic.

        • 1. Re: Unable to persist preferences.

          This is working in CVS Head, so I'm thinking its probably fixed in CR2.

          I have modified the zip in the weatherportlet when logged in, and now it shows the weather in ATL... after login.

          I have modified the newsportlet as well (http://finance.yahoo.com/rss/headline?s=MCD) and it shows me mcdonalds news when logged in.

          • 2. Re: Unable to persist preferences.
            peterj

            I didn't say that the weather portlet was not working. I can see the local weather with it just fine. But the reason that it works is that the processAction methods sets "newZip" in the response parameters and then redirects to the view. The view then uses the "newZip" parameter, and not the value from the preferences. If there is no "newZip" parameter, then the weather in Miami shows, which is what is set in portlet.xml.

            I have been digging through the code and have come to the conclusion that this problem is all related to a configuration setting. That is, if the portlet is configured to treat preferences as read-only, it will ignore all changes. Code in PortletPreferencesImpl.sotre():

            if (prefs.isReadOnly() == false)
            {
             PropertyChange[] changes = (PropertyChange[])updates.values().toArray(new PropertyChange[updates.size()]);
             prefs.update(changes);
            }


            But I have not yet found where the "isReadOnly()" value of "prefs" originates. Seems that every class is getting it from somewhere else. Someone someplace must be setting the original value, but I haven't tracked it down yet.

            This is not to be confused with the user not having write privileges on the preferences, in which case an exception gets thrown when the PortletPreferences.setvalue() method is called (such as when you are not logged into the portal).

            • 3. Re: Unable to persist preferences.
              peterj

              I downloaded jboss-portal-2.4 from CVS, built and deployed it, and then deployed my modified weather portlet, and now the log shows the proper data:

              newZip=92691 RssXml=http://xml.weather.yahoo.com/forecastrss?p=92691

              So you are correct, Roy, it is fixed in CR2. Thanks for the help.