Storing User-Specific Portlet Preferences

Portlets can store user-specific settings (used for personalization purposes, for example) in a number of ways. Our Portal Manager offers three storage variants for such data:

  • In RAM (MemoryPreferencesStorage): This is the fastest method. However, the stored data is lost when the application server is restarted.

  • In the file system (FilesystemPreferencesStorage): The settings are stored as Java preferences in the home directory of the user who has started Trifork server. With many users or many portlets, the storage capabilities may be insufficient. Under Linux, for example, a directory may not contain more than 32.768 directories.

  • In a database (DatabasePreferencesStorage) (from version 6.7.1): Storing the user data in a database is the most flexible method. However, it increases the administrative effort required.

The storage method can be specified by means of a bean in the preferencesStorage property which can be found in the pm.xml file of the portlet web application. Only one of these beans must be used. Therefore, two beans are commented out in the following example.

<property name="preferencesStorage">
  <!-- Store in memory only. Prefs will not survive appserver restart -->
  <!-- bean class="com.infopark.pm.MemoryPreferencesStorage" /> -->
  <bean class="com.infopark.pm.FilesystemPreferencesStorage" />
  <!-- Store in database table. Configure a dataSource bean -->
  <!--
  <bean class="com.infopark.pm.DatabasePreferencesStorage">
    <property name="dataSource" ref="portletPrefsDataSource"/>
    <property name="tableName" value="portlet_prefs"/>
    <property name="portletColumn" value="portlet"/>
    <property name="loginColumn" value="login"/>
    <property name="keyColumn" value="key"/>
    <property name="indexColumn" value="idx"/>
    <property name="valueColumn" value="value"/>
  </bean>
  -->
</property>

No configuration is required for the beans used to store the user settings in RAM or in the file system.

The bean for storing the data in a database assumes that the data source exists and is accessible. The database can be configured by means of the com.infopark.pm.DatabasePreferencesStorage bean which has the following property elements.

  • dataSource: Use the ref attribute to refer to a bean, for example portletPrefsDataSource, which specifies and configures the class to be used for accessing the database. In this example, all access is done via JDBC:

    <bean id="portletPrefsDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName">
        <value>jdbc/portletDB</value>
      </property>
    </bean>
  • tableName: The name of the database table.

  • indexColumn: Name of the primary key column.

  • keyColumn: Name of the column in which the name of the saved value is stored (the portlet and user-specific parameter name).

  • portletColumn: The name of the column in which the portlet ID is stored.

  • loginColumn: The name of the column in which the user name is stored.

  • valueColumn: The name of the column in which the parameter value is stored.

The database interface is only used by the News Portlet included in the Portal Manager. To use the interface for your own portlets in the way shown above, make sure that the following prerequisites are met:

  • Database is available: The database must have been set up and supplied with the database table specified above. The values of all columns except indexColumn have the VARCHAR type. The values of indexColumn have the INT type. The following database command creates such a table:

    CREATE TABLE portlet_prefs (
      idx INT,
      key VARCHAR,
      login VARCHAR,
      portlet VARCHAR,
      value VARCHAR
    )
  • JDBC drivers have been installed: The JDBC driver for your database must have been installed in Trifork server. You can upload the driver by means of the server console.

  • Data source has been set up: In Trifork server, you require a dataSource and a pooledDataSource to access your database via the JDBC driver.

After the database and access to it have been configured, you can store and retrieve user-specific settings via the API of the bean, analogously to the news portlet.