change current page with liferay - liferay

how can i change the current page with liferay, i use themedisplay api. but i didn't find how can i change the current page from web/guest/new to /web/guest/new22. i use the bellow code to get current url
String currentCompleteURL = PortalUtil.getCurrentURL(rdReq);
ThemeDisplay themeDisplay = (ThemeDisplay) rdReq.getAttribute(WebKeys.THEME_DISPLAY);
String title = themeDisplay.getLayout().getName(themeDisplay.getLocale());
System.out.println("title "+title);

If you are just looking to redirect all the request to a particular page(in your case /web/guest/new) to somewhere else(in your case /web/guest/new22), what you can do is go to Manage Page from /web/guest/new page and then select Link to Page from Type drop down. This will show another drop down named "Link to Page" below Type from where you can select the page you want to redirect the user to(web/guest/new22).

Related

Different kind of redirection in a portlet

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.

Navigating in JSF hierarchy up and down

I have a page hierarchy as shown below where everything starts with showing items in a primefaces datatable. For each item a <p:link> or <p:commandlink> is generated.
Click on an item's link should do a redirect to the editItem page with the item's id shown in the query string.
The edit page has a save and cancel button which should redirect back to the listItems page.
The edit page has also a list of subItems, which are shown the same way as in the itemList.
Click on a subItem's link should do a redirect to the editSubSubItem page with the item's id shown in the query string and click on save/cancel should redirect back to the origin editItem page.
Same behavior should be possible for the edit pages editSubItem, editSubSubItem, and so on... Means save/cancel should always redirect back one level in the hierarchy.
http://localhost:8080/myWebApp/listItems.xhtml
http://localhost:8080/myWebApp/editItem&id=123
-> save/cancel - back to listItems
http://localhost:8080/myWebApp/editSubItem&id=456
-> save/cancel - back to editItem&id=123
http://localhost:8080/myWebApp/editSubSubItem&id=789
-> save/cancel - back to editSubItem&id=456
Is there an easy way to achive this kind of hierarchical navigation?
I'am using Primefaces 6.0 and JSF-2.2 on Wildfly-10.0.0.Final
I fixed it by using a Stack<String> object in the SessionMap, where i push the current page url before redirect to another page and pop the origin page on close of the page.

How to tell the context an Xpage is running in - Sidebar

I have an Xpage that I want to put in a panel in the sidebar.
I only want the entry part to be in the panel, so I made a ccEntry Custom Control and I put it into an Xpage for the main app and into an Xpage that is for the widget and ONLY contains the ccEntry form.
When I run the widget in the sidebar and hit submit, the code in the submit (which says previous) goes to the entire page. I want to put something in the button to like if I am in a sidebar then do this else do this. So if I could grab the name of the Xpage in a field that would do, but I cannot figure out how to do this.
Try view.getPageName(). That will give you a string of the current XPage's name in the format "/somepage.xsp".
#Jesse's solution makes something nasty: the control gets tightly coupled to its surroundings. You have two options:
Redirect
Define custom control's parameter with page name or URL to redirect to. Your submit button then redirects to that URL (accessed by compositeData.param). Your pages define different parameter value.
Navigation (preferred)
Your submit button's last command is simple line of code:
return "submitted";
Your pages for app/sidebar define different navigation rule target for the same rule: "submitted".

How to find portlets added on a particular page in Liferay?

How can I find which portlets are added on a particular Liferay page?
For Example:
I have three pages: Welcome, Wiki and Search.
Now all these pages have portlets added on them and some of them are instanceable portlets (like web-content display and iframe portlets).
Now I want to pass some information in the form of request parameters to the iframe-portlet on the Search page from the Welcome page.
I have found two ways to do this:
If you want to find the portlets on the same page in which your portlet is added then, you can make use of themeDisplay object available to your portlet or JSP:
// In JSP
List<String> portletIdList = themeDisplay.getLayoutTypePortlet().getPortletIds();
// In portlet class
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
List<String> portletIdList = themeDisplay.getLayoutTypePortlet().getPortletIds();
If you want to find the portlets on some different page, then you should know three things viz; friendly-url, groupId and whether this page is a public-page or private-page of the Site (or Community), so here is the code:
// 101543 is the SiteId, if it is a public-page then "false" and "/search" is the friendlyURL
LayoutTypePortlet layoutTypePortlet = LayoutTypePortletFactoryUtil.create(LayoutLocalServiceUtil.getFriendlyURLLayout(101543, false, "/search"));
List<String> portletIdList = layoutTypePortlet.getPortletIds();
The portletIdList contains the portletIds complete with their instanceIds. So now from the list you can just filter out the iframe-portlet on the /search page by using com.liferay.portal.util.PortletKeys.IFRAME and you will get something like 48_INSTANCE_rPv9.

Get portlet/page containing web content in Liferay

I'm trying to make the Liferay (6.0.6) Asset Publisher publish all changes across multiple communities on the portal homepage. By clicking on a link the user is supposed to be redirected to another community and see the new web content. The problem is that the default behaviour of asset publisher (even with the hook to gather info from all communities) tries to get the url by searching the group of the current page (in which the content is not).
I decided to change the jsp showing the page to search all pages across all communities and find the first one containing the portlet with the desired web content. So
How could I get the portlet containing the web content by journal id of the web content?
How could I get the page containing the portlet?
Thanks
The PortletPreferences table in the database contains the configurations of each portlet in the system. The configuration of an articleId for a Web Content Display portlet is stored as a preference in this table. If you look at that table, there are 3 important columns:
plid contains the id of the Layout (=page) on which the portlet was dropped.
portletid contains the instance id of the portlet. For Web Content Display portlet, this ID has the format 56_INSTANCE_XXXX where XXXX is a unique hash.
preferences is an XML formatted string of all preferences and their values for this portlet.
An example of the preferences XML:
<portlet-preferences>
<preference><name>group-id</name><value>10139</value></preference>
<preference><name>article-id</name><value>14295</value></preference>
</portlet-preferences>
So it's just a question of getting your SQL queries right. As far as I know, there is no service you can call directly for this.
SELECT l.friendlyURL
FROM PortletPreferences p, Layout l
WHERE p.plid=l.plid
AND p.portletid LIKE '56_INSTANCE_%'
AND p.preferences LIKE '<preference><name>article-id</name><value>14295</value></preference>';
Something like the following allows you to find the Layout on which an article is Rendered.
List<Long> layoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds(groupId, false, articleId);
long layoutId = 0;
if (!layoutIds.isEmpty()) {
layoutId = layoutIds.get(0).longValue();
Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId);
String url = PortalUtil.getLayoutURL(layout, themeDisplay);
...
}

Resources