I want to create a link in a portlet so that I can navigate to a different page in the liferay portal. I order to do that I am looking for an API (can be liferay specific) that given a page name, would return it's url (it can be the friendlyURL as well).
RE: how to get current URLgetURLPortal()+themeDisplay. getURLCurrent()" which gives me exactly the URL that is currently shown in the browser with parameters and everything..
Portal pages in Liferay are indeed called Layouts
in APIs and DB tables. They're identified by plid
field, can be obtained using LayoutLocalServiceUtil
and related APIs, and also from some other calls like themeDisplay.getLayout()
.
However in order to build String containing URL to a page you'll have to concatenate friendly URL of portal, group and layout itself (i.e. /web/guest/home
- web
is portal URL for public pages, guest
is friendly URL of guest group by default and home
is friendly URL of home page/layout by default). This can be tricky, as you have to check whether this is a public or private page, etc.
And once you start using virtual hosts with friendly URLs for groups, things change. So this is not a good way.
To avoid manually creating URLs and have URLs that are guaranteed to be correct you should use com.liferay.portal.util.PortalUtil.getLayoutFriendlyURL(Layout layout, ThemeDisplay themeDisplay)
a static method of PortalUtil
- it'll do all the necessary work for you. Though you also need to provide ThemeDisplay
and not only Layout.
The API to access pages in Liferay is the LayoutService. However, page names are not unique in Liferay and furthermore they are internationalized. So you need some unique property for a page to retrieve its url, besides its name.
If you really only have the page name, you can use LayoutLocalServiceUtil.getLayouts(...) to loop over all Layouts and check for some property (in this case its name).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With