Search code examples
urlliferayportal

Creating links to organization/community pages in Liferay 6


Lets say I have am Organization object. How do I create an url that points to that organization's public pages?

There is a class NavItem that creates links to given layouts, but which one the "front page" is undocumented (among everything else). Then there is PortletURLImpl that can be used (in convoluted way) for this at least as long as user is a member of the community.


Solution

  • A URL to a Liferay page obeys to the following format:

    /[web|group]/[group-friendly-url]/[page-friendly-url]
    
    • The first part decides whether to link to the public (web) or private (group) pages. You can also change these strings inside portal.properties (search for layout.friendly.url.private.group.servlet.mapping and layout.friendly.url.public.servlet.mapping). In that case you should use the configured strings instead of the default ones.
    • The second part is de friendly URL of the group. As you know, each Organization in Liferay is associated with a Group. So you can do something like this: organization.getGroup().getFriendlyURL()
    • The last part is the friendly URL of the page you want to visit. If you don't specify any page, Liferay will automatically redirect to the first page of the group.

    In your case it would thus be sufficient to do:

    String url = "/web"+organization.getGroup().getFriendlyURL();
    

    Good luck!