I am a little confused by Liferay's friendly URL mechanism and utility classes.
Can someone please explain this URL to me in detail?
http://127.0.0.1:8080/web/guest/home
^ ^ ^ ^ ^ ^
Prot. Hostname | | | Layout FriendlyURL
Port | Sitename
???
Part 4 web is a miracle to me and seems to be indicating if the site is staged, public or private?
The next question would be, which UtilClass to use to guarantee that a certain layout exists in that site.
You're right, the web part indicates the the site is public and for private pages ot would be group.
To check if a layout exists get the friendlyUrl of the layout use :
LayoutLocalServiceUtil.getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL)
If this doesn't suit you there are other methods in this class that may.
Liferay Doc: LayoutLocalServiceUtil
Related
I would like to know the different kind of redirections in the portets and how to realize them. How to go from one view (jsp file) to another in the same portlet, how to go from one page to another from a portlet. It is for the purpose of making a form so I would like to do this in a processAction.
Your answer is not clear.
However, in Liferay, you can route your application using urls.
For example, you can create a portlet action url on your own.
You can try something like this:
HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
PortletURL oPortletURL = PortletURLFactoryUtil.create(request, <portletName> , <plid>, <portletPhase>);
oPortletURL.setParameter("myParameter1", "parameter1");
String portletURL = oPortletURL.toString();
Where:
<portletName> is the javax.portlet.name of your portlet
<plid> is the ID of a page where is located an instance of your <portletName> portlet (try to check Layout and LayoutFriendlyUrl tables)
<portletPhase> is the phase you need, for example PortletRequest.ACTION_PHASE
Finally, you can use setParameter() method to pass parameters in query string.
On the jsp for a single portlet: If you use Liferay's MVCPortlet, you can just add the mvcPath parameter with the name of the JSP, to make sure your portlet renders with this JSP. Nothing else.
Pages have a URL. If you want to redirect to another page, you'll have to configure the page's URL somewhere. However, that's rarely done unless you're implementing a Navigation portlet. Your question sounds more like you have a multi-page portlet.
According to the Primefaces 6.2 user guide the attributes stand for
Name | Default | Type | Description
[...]
url | null | String | Url to be navigated when menuitem is clicked
[...]
outcome | null | String | Navigation case outcome
where "outcome" is a synonym of the description for url. I would like to avoid using them wrongly.
The answer is :
outcome refers to a JSF page in your application or a navigation rule defined in your faces-config.xml
url simply opens the given address, which could be on another website.
Using outcome is a great feature, because if the targeted JSF page does not exist, the link is not produced, so you will not have a 404 response when clicking on it.
i had used below code but it is not working.
<#assign navItem = objectUtil("com.liferay.portal.kernel.theme.NavItem") />
it give below error.
Caused by: freemarker.core._TemplateModelException: Java constructor "com.liferay.portal.kernel.theme.NavItem.com.liferay.portal.kernel.theme.NavItem(javax.servlet.http.HttpServletRequest, com.liferay.portal.kernel.model.Layout, Map)" takes 3 arguments, but 0 was given.__----_FTL stack trace ("~" means nesting-related)
I had also used below code it is also not working.
<#assign navItemClass = portal.getClass().forName("com.liferay.portal.kernel.theme.NavItem")>
Basically i want to retrieve NavItem object in theme and want to use it.
The scripting context gets a large part of its variables injected by TemplateContextHelper. In there you can find several relevant values for the underlying problem that you describe in the comment to your question:
layout is representing the current page (layout is the technical name)
layouts is a collection of all pages
the same values can be retrieved through themeDisplay
navItems is a collection of all navItems, but you'll have to find the one relating to the current page yourself. It might be easier to go through layout
Browsing through the TemplateContextHelper sourcecode might give you the hints you need.
I've got to implement navigation using a main menu (easy) but then each menu will lead to a group of pages that have another "submenu" which I've implemented as a menu widget in the before content area.
The main navigation is something like this:
Home | First Group | Some page | Another page | Second Group | Yet another page
When the user clicks Home, Some page, Yet another page, it is taken directly to that page.
If the user clicks any of the "groups" it is taken to the "default page" for that group, and a submenu which is implemented as a menu widget is shown in the before content area. The first group can have 5 pages
Page 1.1 | Page 1.2 | Page 1.3 | Page 1.4 | etc.
The Second Group will have another set of pages.
I've naively set the path properties for the subpages so that they share a common path:
/group-1/page-1-1
/group-1/page-1-2
/group-2/page-1-3
etc.
/group-2/page-2-1
/group-2/page-3-1
etc.
I was expecting to use the Match Path to hide one widget menu in under one path or the other. But the problem is that I can't target a specific Menu or Widget, only content types in general, etc. I can't do something like this:
<Match Path="/group-1/*" ContentType="Widget SOME WAY TO TARGET A SPECIFIC WIDGET!!!">
<!-- SEND THE NEEDED PARTS TO OBLIVION SO THAT ONLY THE CORRECT MENU SHOWS HERE --!>
<Place Parts_Common_Body="-" />
</Match>
I believe that it would be much better to use a layer rule to target a specific path, but I just can't match a layer rule to something like url("/group-1/*"), so that's why I've tried to use the placement info which seems to be the wrong tool.
Is there a way I can extend the layer rules to work with regular expressions, for example? This way I can create really powerful layers and just layout my widgets on the proper layers.
In summary what I want is to have different submenus for different sections of the site. I'm just kind of lost on how to accomplish that, but layer rule seem to be the right tool, only if I could manage to use a little more powerful matching syntax.
I think I'm kind of blind!!!
Straight from the docs:
url("<url path>")
True if the current URL matches the specified path. If you add an asterisk (*) to the end of the path, all pages found in subfolders
under that path will evaluate to true (for example, url("~/home*")).
So adding this rule was enough to create a layer for an entire section of the site:
url("~/group-1*")
I'm almost ashamed of myself...
I have a situation where a class I have is passed a PublishingPage instance and I want to enumerate any and all web part zones that are used in the Layout Page for this page.
This is proving tough.
PublishingPage has a property called Layout, which is of type PageLayout. This is different from PublishingLayoutPage which inherits (eventually) to Page which has the Zones property. This PageLayout type does not have any reference to the normal ASP.NET Page type which has the Zones property I need.
I can get an SPListItem and a SPFile from the PublishingPage.Layout property, and get the contents of the page layout in raw text form, but this can't be parsed with XmlReader as it's not valid XML (has <% tags which are invalid).
I can get an SPWeb from PublishingPage.ListItem.Web, and this can get me an SPLimitedWebPartManager, where I can get a collection of LimitedWebParts (which has Zone information) - but this won't help because at this stage of my code I have no web parts.
I'm pretty stuck, it looks like the Publishing Infrastructure is quite detached from both ASP.NET and SharePoint.
UPDATE:
I can use the SPLimitedWebPartManager to add a dummy web part (like a new ContentEditorWebPart) to a web part zone (I have the names of the zones that are used), but when I save this out and check the page back in (and get a new SPLWPM), I can get the WebParts back but the Zone property is null (the ZoneID property is populated and correct).
The posts from Wayne Fan on this thread seem to cover what you're trying to do. Hope this helps.