Programmatically get the url of a page in liferay - liferay

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).

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).

At least in Liferay 6.1.20 one can use 'Link Portlet URLs to Page' to make links proceed to antoher page in your portal. It is under ´look and feel´ menu item of your portlet. For me this works fine.
cheers

try this one for current url
${themeDisplay.getURLCurrent()}
try this one for portal url
${themeDisplay.getPortalURL()}

Related

Which controller builds the home page?

I need to block anonymous from entering the site, but I can't find the controller that builds the Home page nor the routing that redirects there.
Going to the widget admin and unpublishing/deleting everything in the anonymous layer, only hides the items but I need to redirect to the login page, just as the Admin area functionality.
And I cant' just remove the anonymous role, because they can access some pages and content, just not the Home.
Orchard, by default (though you can override this, see the blog module), uses the same controller to render all content items, including the home page.
What you need is the content permissions module, that has a part you can attach to content types (e.g. Page) that will let you specify, per item, what roles can view it. Attaching this and setting only authenticated to view your home page should redirect to the login page as desired.

Private Pages Navigation in Liferay 7

we´re starting our very first liferay 7 project and I am having troubles creating private user pages. We have 7 Pages that we want the user to have and those pages need to be private because we want to use the private messaging portlet.
I created a site template and I assigned it to my new user´s dashboard.
So the pages get created and the user has access to them (I verified by entering the URLs manually).
But how can the user navigate ? I haven´t found any way to show the available pages to the user. The Menu only allows the user to click on "My Dashboard" and that´s it ...
Any help is welcome.
Best regards,
Daniel
You need to give friendly url first to your site
You can give in site by changing the friendly url.
You can also provide different urls for private as well as public pages.
For public pages liferay appends web /your-friendly-url
and for private pages it appends group /your-friendly-url
Then give the url under Control Panel-->Configuration-->Instance Settings
and set the Default Landing Page property to /group/your-friendly-url.
They have mentioned it clearly as stated below:
Enter the friendly URL that is used by both public and private pages. The friendly URL is appended to http://ip/web for public pages and http://ip/group for private pages.

WebSphere Portal - Retain friendly URL after Portlet Action/Render call

I have implemented friendly URL in WebSphere Portal 7.0. So lets say I have page with friendly URL "test" and a portlet added to the page. When I hit Portal URL /wps/myportal/test, the page is loaded with no junk characters(no state information). But as soon as I click on any button inside portlet(any action call to Portlet) I see that the junk characters comes back.
Is there a way to keep URL friendly all the time? How can we avoid generating junk characters on portlet action/render calls?
Note:- We have different portlets for different pages and they were developed based on different framework (Spring, Struts, JSR 286 etc)..
in 7.0 by default no, the action url is needed to tell portal what portlet to target. What you could do is use the resourceAction and do everything rest based and avoid the action url, or set up a servlet to handle actions for the portlet and handle urls through that as well in a rest manner.
You could also redirect after the action url back to a friendly url in your portlet code

Liferay Top Level Friendly URL

Is there a way to create / process friendly URLs in liferay like this?
http://myserver.com/JonDoe
... where John Doe is the name of a clients whose data should be displayed.
A little more detail:
I am not talking about getting rid of the "web" or "group" for friendly urls, I am taking about having a friendly url right after the first "/".
We want to create URLs in the form of http://server/ClientName where ClientName resolves to the name of a Client. This is an issue since normally liferay would expect a friendly URL after the first "/". So we ned to intercept that somehow.
The process should be like this (pseudo code):
1) inspect values after first "/"
2) If value after "/" is the name of a client, send user to client display page and display client information
3) If there is no client with the given name, interpret it as friendly url and do normal liferay behaviour.
Is there a way to do this in liferay ?
Sounds like you want to get rid of the /web/ or /group/ parts of the URLs? This is possible with proper configuration of the virtual host - you'll map the site to the domain name, then you have total freedom to name the pages, even hierarchically (e.g. /JonDoe/home)
So far this was simple configuration. If you want /JonDoe to point to another site than /JoeShmoe (e.g. just get rid of /web/ or /group/), you'll have to dig deeper and write quite some customization plugins that change the name resolving (and generation of URLs)
If you want to have one URL for a page, you can just set the friendly URL for that page (see Olafs remark about virtual hosts as well)
If you want to have a limited set of URLs for one page, you can create a page of type Link to Page for each URL and select the original page. To identify the current URL when rendering you portlet you can use PortalUtil.getCurrentURL(renderRequest)
If you want to have many URLs for one page you could use a FriendlyUrlMapper, which allows URLs like http://myserver.com/page/-/myPortlet/JonDoe.
If you want to have many "root" URLs (i mean without the /page/-/myPortlet part), you will have to create an Liferay EXT plugin, extend com.liferay.portal.util.PortalImpl and overwrite getPortletFriendlyURLMapperLayoutQueryStringComposite. I've done the same by implementing a strategy that checks if a page exists for a specific given URL and otherwise uses the URL as parameter for a FriendlyURLMapper.

Links on SharePoint 2010 Master Page not changed based on Alternate Access Mappings

We are creating a custom branded Master Page in SharePoint 2010. To make the page similar to a legacy page we have implemented an html based custom dropdown navigation menu we had in place directly on the Master Page (consisted of basic HTML elements ULs and LIs with A tags styled with a CSS class).
I assumed the links from the basic HTML on the page would be subject to Alternate Access Mappings currently in place, but it seems to not be the case. On a test page opened in 3 different URLs (http://sharepoint2010, http://sharepoint2010.mydomain.com, https://sharepoint2010.mydomain.com) the links from a WIKI page are modified as I expected, but the links from the Custom Navigation Menu (plain HTML on the Master Page) are not modified.
I can see where that would be useful... But is there a way that I can add links on the MasterPage in a way that SharePoint parses them first, making them subject to Alternate Access Mapping translation? I tried placing a link inside a SPLinkButton control, but it didn't achieve the desired behavior.
e.g.
<ul id="navmenu">
<li><SharePoint:SPLinkButton runat="server" NavigateUrl="http://sharepoint2010">sharepoint link</SharePoint:SPLinkButton></li>
<li>sharepoint2010</li>
<li>test</li>
</ul>
When I access the page via https://sharepoint2010.mydomain.com the links above are still http://sharepoint2010 rather than https://sharepoint2010.mydomain.com
Any thoughts?
Thanks,
Victor
EDIT (clarify):
I was planning on using relative links as a fallback. But for the purpose of what we are doing it would be more maintainable if we could keep the full links and use AAM.
I'm aware that standard relative links are a possibility. I was hoping to identify if there is a way to use AAM on Master Page content (or even on Content Retrieved from External Services down the road) by providing a specific link syntax, or control framework.
There is no need to re-insert the host name if your links are on the same domain and you're not using managed paths. Keeping your links relative will ensure that any bindings in IIS and AAM setup in SharePoint will work without any additional work.
Otherwise, I would heavily suggest to use the available ~sitecollection and ~site SPUrl token to retrieve the current site collection url or current web url. You need to wrap it in anything running server side as the expression will be handled ... server side.
eg:
<asp:Literal runat="server" Text="<% $SPUrl:~site/press-releases/ %>"/>
Hope it helped
When you use the NavigateUrl= attribute of the SPLinkButton, SharePoint renders a simple anchor with href= instead of regular PostBack JavaScript code. Alternate access mapping do not play a role here.
If its simply relative links you want, then leave out the dns entry altogether (ie the bit of the url you are switching with your AAM) and begin the url with a forward slash to make it relative. If this doesn't meet your needs, the way Sharepoint does it is with a relative url token. Have a look in v4.master for the tilda character followed by 'site' or 'sitecollection' which refers to the current web and site collection respectively. Copy this method. For more details, look at this link: http://msdn.microsoft.com/en-us/library/ms473643.aspx

Resources