1. Portlets

Liferay Portal Enterprise builds upon the Portlet API (JSR 168) to provide users with a rich set of portlets. The following are examples from the portlets bundled with Liferay. Follow the instructions found in Hot Deploy to learn how to hot deploy external WARs that are not bundled with Liferay.

1.1. Hello World

  1. This portlet is defined in /portal-web/docroot/WEB-INF/portlet.xml.

          <portlet>
              <portlet-name>47</portlet-name>
              <display-name>Hello World</display-name>
              <portlet-class>
                 com.liferay.portlet.helloworld.HelloWorldPortlet
              </portlet-class>
              <expiration-cache>0</expiration-cache>
              <supports>
                  <mime-type>text/html</mime-type>
              </supports>
              <portlet-info>
                  <title>Hello World</title>
                  <short-title>Hello World</short-title>
                  <keywords>Hello World</keywords>
              </portlet-info>
              <security-role-ref>
                  <role-name>Power User</role-name>
              </security-role-ref>
              <security-role-ref>
                  <role-name>User</role-name>
              </security-role-ref>
          </portlet>

    The unique id associated with this portlet is 47. The HelloWorldPortlet class extends javax.portlet.GenericPortlet. The source of this class shows that it does nothing more than print out Hello World. This portlet is viewable by HTML browsers. The title is defined in portlet-info. Users must have either the Power User or User role to access this portlet. The roles can be changed at run time via the Admin portlet.

  2. Additional definitions for this portlet are found in /portal-web/docroot/WEB-INF/liferay-portlet.xml.

    <portlet id="47" struts-path="hello_world" narrow="true" />

    The id value in liferay-portlet.xml must match the portlet-name value in portlet.xml. The struts-path value tells Struts that all requests starting with http://localhost/c/hello_world/* are considered part of this portlet's scope. See the Mail portlet to better understand this feature. The narrow value, if set to true, means this portlet will be rendered in the narrow column. This value can be changed at run time via the Admin portlet.

  3. Display information for this portlet is found in /portal-web/docroot/WEB-INF/liferay-display.xml and makes it possible for users to add this portlet via the personalize pages screen.

    <category name="category.test">
        <portlet id="47" />
        <portlet id="48" />
    </category>

    When a user goes to personalize pages and clicks on a category to choose a portlet, the Hello World portlet is available under the category with the name that matches the key category.test. The value for this key is defined in /portal-ejb/classes/content/Language.properties.

    category.test=Test

1.2. IFrame

  1. This portlet is defined in /portal-web/docroot/WEB-INF/portlet.xml.

          <portlet>
              <portlet-name>48</portlet-name>
              <display-name>IFrame</display-name>
              <portlet-class>com.liferay.portlet.IFramePortlet</portlet-class>
              <expiration-cache>0</expiration-cache>
              <supports>
                  <mime-type>text/html</mime-type>
                  <portlet-mode>edit</portlet-mode>
              </supports>
              <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
              <portlet-preferences>
                  <preference>
                      <name>src</name>
                      <value>http://www.gfa.org</value>
                  </preference>
                  <preference>
                      <name>auth</name>
                      <value>false</value>
                  </preference>
                  <preference>
                      <name>auth-type</name>
                      <value>basic</value>
                  </preference>
                  <preference>
                      <name>form-method</name>
                      <value>post</value>
                  </preference>
                  <preference>
                      <name>user-name</name>
                      <value></value>
                  </preference>
                  <preference>
                      <name>password</name>
                      <value></value>
                  </preference>
                  <preference>
                      <name>hidden-variables</name>
                      <value>var1=hello;var2=world</value>
                  </preference>
              </portlet-preferences>
              <security-role-ref>
                  <role-name>Power User</role-name>
              </security-role-ref>
              <security-role-ref>
                  <role-name>User</role-name>
              </security-role-ref>
          </portlet>

    The unique id associated with this portlet is 48. The IFramePortlet class extends javax.portlet.GenericPortlet. The source of this class shows that this class prints an IFRAME tag that references an external site. This portlet is editable and viewable by HTML browsers. The preferences bind the name src with the default value of http://www.gfa.org.

    The auth value, if set to true, will attempt to authenticate the user to the external IFrame application. The auth-type value can be set to basic or form. Basic authentication appends the login information to the URL and form authentication requires a post to the external IFrame application. The form-method value can be set to get or post. This is only used if you are using form authentication. The user-name value sets the user name for authentication. If you are using basic authentication, then you just need to set the user name. If using form authentication, you need to set the user name as a key value pair like acme_login=test@acme.com. The password value sets the password for authentication. If using basic authentication, you just need the password. If using form authentication, set the password as a key value pair like acme_password=password. The hidden-variables value is used for form authentication. Some forms require certain prepopulated fields in order to proceed with authentication. Separate each key and value with a = and each key value pair with a ;. Users must have either the Power User or User role to access this portlet. The roles can be changed at run time via the Admin portlet.

  2. The title is fetched by StrutsResourceBundle and is configured in /portal-ejb/classes/content/Language.properties.

    javax.portlet.title.48=IFrame
  3. Additional definitions for this portlet are found in /portal-web/docroot/WEB-INF/liferay-portlet.xml.

    <portlet id="48" struts-path="iframe" />

    The id value in liferay-portlet.xml must match the portlet-name value in portlet.xml. The struts-path value tells Struts that all requests starting with http://localhost/c/iframe/* are considered part of this portlet's scope. See the Mail portlet to better understand this feature.

  4. Display information for this portlet is found in /portal-web/docroot/WEB-INF/liferay-display.xml and makes it possible for users to add this portlet via the personalize pages screen.

          <category name="category.test">
              <portlet id="47" />
              <portlet id="48" />
          </category>

    When a user goes to personalize pages and clicks on a category to choose a portlet, the IFrame portlet is available under the category with the name that matches the key category.test. The value for this key is defined in /portal-ejb/classes/content/Language.properties.

    category.test=Test

1.3. Calendar

  1. This portlet is defined in /portal-web/docroot/WEB-INF/portlet.xml.

          <portlet>
              <portlet-name>8</portlet-name>
              <display-name>Calendar</display-name>
              <portlet-class>com.liferay.portlet.JSPPortlet</portlet-class>
              <init-param>
                  <name>view-jsp</name>
                  <value>/portlet/calendar/view.jsp</value>
              </init-param>
              <expiration-cache>0</expiration-cache>
              <supports>
                  <mime-type>text/html</mime-type>
              </supports>
              <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
              <security-role-ref>
                  <role-name>Power User</role-name>
              </security-role-ref>
              <security-role-ref>
                  <role-name>User</role-name>
              </security-role-ref>
          </portlet>

    The unique id associated with this portlet is 8. The JSPPortlet class extends javax.portlet.GenericPortlet. The source of this class shows that this class looks for the init parameters and forwards to the appropriate JSP depending on the portlet mode. This portlet is viewable by HTML browsers. Users must have either the Power User or User role to access this portlet. The roles can be changed at run time via the Admin portlet.

  2. The title is fetched by StrutsResourceBundle and is configured in /portal-ejb/classes/content/Language.properties.

    javax.portlet.title.8=Calendar
  3. Additional definitions for this portlet are found in /portal-web/docroot/WEB-INF/liferay-portlet.xml.

          <portlet
              id="8"
              struts-path="calendar"
              scheduler-class="com.liferay.portlet.calendar.job.Scheduler"
              preferences-sharing-type="user"
              show-portlet-access-denied="true"
              show-portlet-inactive="true"
          />

    The id value in liferay-portlet.xml must match the portlet-name value in portlet.xml. The struts-path value tells Struts that all requests starting with http://localhost/c/calendar/* are considered part of this portlet's scope. See the Mail portlet to better understand this feature. The scheduler-class value must be a class that implements Scheduler and is called to schedule Quartz jobs for this portlet. The preferences-sharing-type value indicates the preferences sharing type of the portlet. If set to none, preferences are not shared and each page will have its own set of preferences. If set to user, preferences are shared by user if the portlet is in a personal page or by group if the portlet is in a group page. If set to company, preferences are shared across the entire company. The show-portlet-access-denied value, if set to true, means non-permissioned users are shown that they do not have access to the portlet. The default value is set in portal.properties. The show-portlet-inactive value, if set to true, means users are shown that the portlet is inactive (if the portlet is inactive). The default value is set in portal.properties.

  4. Display information for this portlet is found in /portal-web/docroot/WEB-INF/liferay-display.xml and makes it possible for users to add this portlet via the personalize pages screen.

          <category name="category.community">
              ...
              <portlet id="8" />
              ...
          </category>

    When a user goes to personalize pages and clicks on a category to choose a portlet, the Calendar portlet is available under the category with the name that matches the key category.community. The value for this key is defined in /portal-ejb/classes/content/Language.properties.

    category.community=Community

1.4. Message Boards

  1. This portlet is defined in /portal-web/docroot/WEB-INF/portlet.xml.

          <portlet>
              <portlet-name>19</portlet-name>
              <display-name>Message Boards</display-name>
              <portlet-class>com.liferay.portlet.messageboards.MBPortlet</portlet-class>
              <init-param>
                  <name>edit-jsp</name>
                  <value>/portlet/message_boards/edit.jsp</value>
              </init-param>
              <init-param>
                  <name>view-jsp</name>
                  <value>/portlet/message_boards/view.jsp</value>
              </init-param>
              <expiration-cache>0</expiration-cache>
              <supports>
                  <mime-type>text/html</mime-type>
                  <portlet-mode>edit</portlet-mode>
              </supports>
              <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
              <portlet-preferences>
                  <preference>
                      <name>messages-per-page</name>
                      <value>25</value>
                  </preference>
              </portlet-preferences>
              <security-role-ref>
                  <role-name>Power User</role-name>
              </security-role-ref>
              <security-role-ref>
                  <role-name>User</role-name>
              </security-role-ref>
          </portlet>

    The unique id associated with this portlet is 19. The MBPortlet class extends JSPPortlet. This portlet is editable and viewable by HTML browsers. The preferences bind the name messages-per-page with the default value of 25. Users must have either the Power User or User role to access this portlet. The roles can be changed at run time via the Admin portlet.

  2. The title is fetched by StrutsResourceBundle and is configured in /portal-ejb/classes/content/Language.properties.

    javax.portlet.title.19=Message Boards
  3. Additional definitions for this portlet are found in /portal-web/docroot/WEB-INF/liferay-portlet.xml.

    <portlet id="19" struts-path="message_boards" 
    indexer-class="com.liferay.portlet.messageboards.util.Indexer" 
    preferences-sharing-type="user" />

    The id value in liferay-portlet.xml must match the portlet-name value in portlet.xml. The struts-path value tells Struts that all requests starting with http://localhost/c/message_boards/* are considered part of this portlet's scope. See the Mail portlet to better understand this feature. The indexer-class value must be a class that implements Indexer and is called to create or update a search index for this portlet. The preferences-sharing-type value indicates the preferences sharing type of the portlet. If set to none, preferences are not shared and each page will have its own set of preferences. If set to user, preferences are shared by user if the portlet is in a personal page or by group if the portlet is in a group page. If set to company, preferences are shared across the entire company.

  4. Display information for this portlet is found in /portal-web/docroot/WEB-INF/liferay-display.xml and makes it possible for users to add this portlet via the personalize pages screen.

          <category name="category.community">
              ...
              <portlet id="19" />
              ...
          </category>

    When a user goes to personalize pages and clicks on a category to choose a portlet, the Message Boards portlet is available under the category with the name that matches the key category.community. The value for this key is defined in /portal-ejb/classes/content/Language.properties.

    category.community=Community

1.5. Mail

  1. This portlet is defined in /portal-web/docroot/WEB-INF/portlet.xml.

          <portlet>
              <portlet-name>1</portlet-name>
              <display-name>Mail</display-name>
              <portlet-class>com.liferay.portlet.mail.MailPortlet</portlet-class>
              <init-param>
                  <name>view-jsp</name>
                  <value>/portlet/mail/view.jsp</value>
              </init-param>
              <expiration-cache>0</expiration-cache>
              <supports>
                  <mime-type>text/html</mime-type>
                  <portlet-mode>edit</portlet-mode>
              </supports>
              <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
              <portlet-preferences>
                  <preference>
                      <name>html-format</name>
                      <value>true</value>
                  </preference>
                  <preference>
                      <name>forward-address</name>
                  </preference>
                  <preference>
                      <name>signature</name>
                  </preference>
                  <preference>
                      <name>col-order</name>
                      <value>fsdz</value>
                  </preference>
                  <preference>
                      <name>order-by-col</name>
                      <value>d</value>
                  </preference>
                  <preference>
                      <name>order-by-type</name>
                      <value>desc</value>
                  </preference>
                  <preference>
                      <name>messages-per-portlet</name>
                      <value>5</value>
                  </preference>
                  <preference>
                      <name>messages-per-page</name>
                      <value>25</value>
                  </preference>
                  <preference>
                      <name>message-headers</name>
                      <value>1</value>
                  </preference>
                  <preference>
                      <name>include-original</name>
                      <value>true</value>
                  </preference>
                  <preference>
                      <name>original-text-indicator</name>
                      <value>0</value>
                  </preference>
                  <preference>
                      <name>reply-to-address</name>
                  </preference>
                  <preference>
                      <name>new-mail-notification</name>
                      <value>2</value>
                  </preference>
                  <preference>
                      <name>folder-names</name>
                  </preference>
                  <preference>
                      <name>blocked</name>
                  </preference>
              </portlet-preferences>
              <security-role-ref>
                  <role-name>Power User</role-name>
              </security-role-ref>
              <security-role-ref>
                  <role-name>User</role-name>
              </security-role-ref>
          </portlet>

    The unique id associated with this portlet is 1. The MailPortlet class extends JSPPortlet. This portlet is editable and viewable by HTML browsers. Users must have either the Power User or User role to access this portlet. The roles can be changed at run time via the Admin portlet.

  2. The title is fetched by StrutsResourceBundle and is configured in /portal-ejb/classes/content/Language.properties.

    javax.portlet.title.1=Mail
  3. Additional definitions for this portlet are found in /portal-web/docroot/WEB-INF/liferay-portlet.xml.

    <portlet id="1" struts-path="mail" preferences-sharing-type="user" />

    The id value in liferay-portlet.xml must match the portlet-name value in portlet.xml. The struts-path value tells Struts that all requests starting with http://localhost/c/mail/* are considered part of this portlet's scope. If a user's request path falls inside the defined struts-path, then all of the portlet's objects will be available inside the forwarded Action classes and JSP pages as defined in /portal-web/docroot/WEB-INF/struts-config.xml and /portal-web/docroot/WEB-INF/tiles-defs.xml. For example, if the user requests http://localhost/c/mail/view_folder, then the user is forwarded to ViewFolderAction. This class has access to the javax.portlet.PortletConfig, javax.portlet.RenderRequest, and javax.portlet.RenderResponse objects through the user's request. These objects are stored as request attributes with the class names as keys. The JSPs that Struts forward to have access to these objects via the <portlet:defineObjects /> tag. User are not allowed to access any paths that fall in http://localhost/c/mail/* unless the have the required roles to access this portlet.

  4. Display information for this portlet is found in /portal-web/docroot/WEB-INF/liferay-display.xml and makes it possible for users to add this portlet via the personalize pages screen.

          <category name="category.community">
              ...
              <portlet id="1" />
              ...
          </category>

    When a user goes to personalize pages and clicks on a category to choose a portlet, the Mail portlet is available under the category with the name that matches the key category.community. The value for this key is defined in /portal-ejb/classes/content/Language.properties.

    category.community=Community