How to Create a Dynamic Page for Terms of Use

Introduction #

Liferay has a feature that allows forcing all users to accept a Terms of Use text before using the portal for the first time. A default text is included with the portal but in most installations using this feature this text will need to be customized. The simpler way to change that text is to modify the following JSP:

/html/portal/terms_of_use.jsp

That is probably all you need for simple sites, but for more complex ones it's useful to find a solution that allows changing the text of the Terms of Use dynamically. For example, by using a Web Content article (formerly Journal article). This solution is very useful when:

  • The terms of use change frequently
  • There is a need to have its text translated to several languages
  • You want to use the established mechanics of Liferay to modify this text instead of having to get administrative access to change an already deployed jsp.

The following section explains how to achieve this.

Using a Web Content Article to manage the Terms of Use #

Using a Web Content Article to change the text of the Terms of Use varies depending on the version you use.

Liferay 5.2.x#

There are now properties you can use to specify an article to use and no code need by modified as the logic has been integrated into the portal. Use these values in your portal-ext.properties:

    #
    # Specify the articleId of a Journal Article to use for the terms of use.
    #
    terms.of.use.journal.article.id=

    #
    # Specify the groupId of the group to which the Journal Article specified by
    # "terms.of.use.journal.article.id" belongs.
    #
    terms.of.use.journal.article.group.id=

Note#

The groupId should be the identifier of the community where the article was created. Again, if you don't want to hardcode this id use the GroupService to obtain it dynamically from the community name. You can locate the GroupId for the Edit view on the Communities portlet, or from the Edit view of a particular Organization.

Prior to 5.2#

Note: This does not apply to all versions prior to 5.2 - see below if you are about to configure an older version - This article just mentioned "older" and "more recent" versions, I don't know when the changes occurred (somebody who knows should add this information)

You'll have to modify the following JSP:

/html/portal/terms_of_use.jsp

You can directly specify the articleId and groupId to the tag:

<liferay-ui:journal-article articleId="TERMS-OF-USE" groupId="<%= groupId %>" />

Older versions of Liferay#

You'll have to modify the following JSP:

/html/portal/terms_of_use.jsp

Remove all the text inside (but leave the form!) and copy it to a Journal Article of your choice. When creating the article give it an id that is easy to remember (if your portal is configured to allow for manual ids), such as TERMS-OF-USE.

Once the article is created you'll have to find it's resource primary key. As of now the UI doesn't show it, so you'll have to go to the database. If you gave the article an easy to remember id it'll be easier to find. Once you have the primary key add the following to the JSP above instead of the terms of text:

 <liferay-ui:journal-article articleResourcePrimKey="<%= articleResourcePrimKey %>" />

If you don't want to hardcode the primary key of the article, you can obtain it using the Journal services from the groupId and the article id, for example:

<% JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, "TERMS-OF-USE");
long articleResourcePrimKey = article.getResourcePrimKey(); %>
<liferay-ui:journal-article articleResourcePrimKey="<%= articleResourcePrimKey %>" />
0 Attachments
14446 Views
Average (0 Votes)
Comments

Showing 7 Comments

Joshua Asbury
9/16/08 5:00 AM

Now, that's handy!

Jonas Yuan
9/16/08 9:18 AM

This is very useful for dynamic web sites!

Markus Lindgren
6/3/09 5:21 AM

Great feature!
Now all administrators on our project can manage the Terms of use instead of the developers.

Peter B West
8/28/09 4:06 AM

I can't get this to work in 5.2.1.

I have a Web Content document. I Assume that the JournalArticle table covers what is now known as Web Content. I'm assuming that group.id is groupId and article.id is articleId from the JournalArticle table. Is this correct? If so, I can't see the article. The item above indicates that the correct field is resourcePrimKey, but that doesn't work either. Has anyone got this to work?

Fabio F
10/16/09 4:41 AM

This feature works only if you have same terms of use for all portal instances.
I need to use a customized terms of use for every portal instance and there insn't an instance property to do this. Only a global terms of use is allowed, isn't it?

Fabio

Armando Ota
11/26/09 6:39 AM

so ... how can I set different "terms of use" for different organizations ???

Ed Holderman
8/23/11 9:43 AM

I believe instance-specific settings are still not possible out of the box: http://issues.liferay.com/browse/LPS-15102 . Is everyone just implementing their own T&C logic to pull up the instance, community, or organization-specific T&C article using a more dynamic way?