title: How to take portlet preferences correctly in Liferay?
body: <p>If a portlet is a web application, then why portlet preferences are taken from ServletRequest (at request scope)?</p>
  
  <p><a href="http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/util/PortalUtil.html#getPreferences(javax.servlet.http.HttpServletRequest" rel="nofollow">http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/util/PortalUtil.html#getPreferences(javax.servlet.http.HttpServletRequest</a>)</p>
  
  <p>How is it possible to take preferences object at application scope?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I am obtaining portlet preferences in the following way. Is it correct? prefs member below is at application scope.</p>
  
  <pre><code>private synchronized void setupPreferences(HttpServletRequest request) {
      // creating preferences
      if( prefs == null ) {
  
          prefs = PortalUtil.getPreferences(request);
          if( prefs != null ) {
              System.out.println("Preferences were taken from request");
          }
  
          String portletResource = ParamUtil.getString(request, "portletResource");
          if (Validator.isNotNull(portletResource)) {
              try {
                  System.out.println("Replacing preferences from 'portletRecource' parameter");
                  prefs = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
              } catch (SystemException e) {
                  e.printStackTrace();
              } catch (PortalException e) {
                  e.printStackTrace();
              }
          }
  
          if( prefs == null ) {
              System.out.println("Preferences were NOT obtained yet");
          }
          else {
              System.out.println("Preferences are OK");
          }
  
      }
  }
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I am using also servlets and static objects in my application. Static objects are in application scope as one can know. I wonder can I keep portlet preferences object in some static object or I need to reobtain it from request each time?</p>
  
  <p>Actually I already assumed this and it works but I wish to know is it correct?</p>