I have two portlets at the same page. Portlet A does a very quick task, and Portlet B does a very slow task. Portlet B reads a parameter from A. If I make a change on A (with RenderURL), Liferay renders whole page (including slow Portlet B). How can I say Liferay to render only Portlet A and not Portlet B?
the renderURL will always point to the whole page. If you go "manual", e.g. without other framework's help, you'll need to utilize the resourceURL and refresh your portlet's content with Ajax.
Another option is to declare your slow portlet B as asynchronous ("ajaxable") and cache the output so that you don't have to constantly do expensive render operations. The ajaxable option is available in liferay-portlet.xml and is documented for that file. The RSS portlet (Liferay-OOTB) is configured like this as it might take a while until this portlet has collected all of its RSS feeds and can render. This might be a good blueprint for your required changes.
Related
I want to serve some data from an static url in Liferay. For example, say to serve a json containing the logged user from "http://server.com/whatever/user" so all the portlets in the proyect can read it. Right now I can do it with a portlet, but then I have to set the url with the configuration panel and I don't like that.
I've seen that I can put jsp files with the static content, but don't know how to access the information of session, users, etc.
Friendly urls seem to accomplish something similar but seem overly complicated and focused in getting a short easy url, something I don't care.
So, how can I get some internal data in an static url (I don't mind if it's friendly, long or short, but always the same) so every element of a Liferay proyect can read it?
FOURTH EDIT: Another way to put it...
In my eclipse I have this tree:
/whatever-war/docroot/html/fancy-porlet/list.jsp
How do I access that jsp in a browser without having to go the Liferay panel and putting the portlet in the menus of the web?
FIFTH EDIT: I haven't had the time to research any more, but I have this in my notes...
https://server/language/c/portal/layout?p_l_id=plid
This goes straight to the portlet, sometimes. plid comes from
PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), name_of_portlet_and_war)
It's no solution for me because, it doesn't always work. Sometimes you get a numeric identifier, sometimes you get a zero. I'd bet on the name of portlet and war being incorrect so it doesn't find the portlet, but then, how do you find the new name of the portlet? Sadly, I discarded the code where the name came from, but is coming from Liferay.
SIXTH EDIT: What I want to do is to be able to call a fixed url, with some data internal to Liferay, and get information based on that data back.
There are several aspects here:
Every portlet already has access to the user through a request attribute called ThemeDisplay:
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Check ThemeDisplay's interface for the various options that you have in order to get the current user's id or object.
You've asked about JSON delivery - this will need to go through Liferay and not (directly) through a JSP in your individual web application. The reason is that any request processed by Liferay will contain the user's information, but as any proper webapp, it's completely separate from any request directed at another webapp: Unless included by Liferay, your JSP will have a different session that has nothing to do with Liferay's session. (I hope this explanation makes sense)
If you write a servletFilter hook, you might not yet have the portal context initialized (Liferay 6.x has been a while for me, pardon for being vague here). If you're on the portlet side, you might have to do more than you expected.
One option that you have is to embed a portlet on every page, automatically (e.g. when it's deployed, it's available). You can configure a portlet to be automatically included on every page, it's done for the chat portlet, for example. That portlet does not need to have any UI, it just needs to expose its resourceURL, so that you can use it from everywhere.
However, I somehow doubt that you use it, given that every portlet has the information already at hand.
But I might also just not understand all of your requirements...
Liferay 7 uses SennaJS as its Single Page Application engine in order to load and replace certain parts of the portal page during form submission and navigation. Occasionally this feature interferes with my use case, so how can I disable it?
If you want to disable the XHR GET navigation performed by SennaJS or its handling of form submissions, you can try one of the following:
If you want to disable SPA for only certain forms or links, you can add the data-senna-off="true" attribute to those <form> or <a> tags.
If you want to disable SPA for only one portlet, you can add <single-page-application>false</single-page-application> to the <portlet> section of your liferay-portlet.xml (see the DTD for the expected order of liferay-portlet.xml elements).
If you want to disable SPA for only one OSGi module portlet, you can add "com.liferay.portlet.single-page-application=false" to your portlet metadata.
If you want to disable SPA on a portal wide basis, you can add javascript.single.page.application.enabled=false to your portal-ext.properties file.
Suppose you have a JSF portlet, where users from different UserGroups are logging in. And you want to check their userGroup and let them land on different Facelets pages, instead of the one stated in portlet.xml
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/html/users/userView.xhtml</value>
<!--
<value>/html/admins/adminView.xhtml</value>
-->
</init-param>
Actually I have a more complex business Logic, so I created a method on a managed Bean that decides on which page the user should land.
What would be the best way to manage their landing page, other than creating a different portlet (different landing page) for each UserGroup ?
I'm using primefaces 3.5 and Liferay 6.1.0 ga1, if that helps
EDIT: Just to make myself more clear, I don't specifically need to change the javax.portlet.faces.defaultViewId.view, although I thought of that too. Anything that lets me land the user on a different page, based on the outcome of a bean's method, would be OK
If this was another page, I would call an action that returns the page as String, but since this is the first portlet page, I just can't find a way to interrupt my bean's method
I'm trying to figure out how to link to another page within the same liferay site.
Obviously I could hardcode the url in my portlet's view but I'm worried about having to update all of my portlets in case the friendly url changes in the future.
I know the name of the page I'm trying to link to, but what if the page name changes too?
I've found infinity of classes that have methods that return friendlyUrls, such as PortalUtil, LayoutLocalServiceUtil, and even LayoutFriendlyURLLocalServiceUtil, but they all require parameters that I'm not sure how to obtain.
Is there a standard way of obtaining friendly urls in liferay?
If you want to link to another Page, you can either use LayoutId or friendly url names.
Both are unique for each companyId, so you are going to be pretty safe using them.
You can set the friendlyUrl as a PortletConfig parameters, so you can set them on portlet Level, and you won't have them hard-coded in your Portlet. Alternatively, you can also save them as custom params in portal-ext.properties (will apply for all portlets of that portal).
Now, that's a lot of code for this, so if you're dealing with specific problems, like creating Portlet Configuration or Reading portal-ext.properties, or creating renderUrls programatically, you should start new questions
I have passed a render parameter from one portlet to another using user friendly url navigation.
response.setRenderParameter("params", renderParams);
response.sendRedirect(response.encodeURL("/wps/myportal/Home/abcPortlet"), "params");
Here Home and abcPortlet are user friendly page names for specific pages.
While debugging I found that OriginalParameterMap contains the render parameter in its URL.
Can someone tell me how to retrieve it? As usual getter methods are not able to retrieve that value.
You cannot pass render parameters from one portlet to another. It has to be Pubic Render Parameter (PRP). The approach of setting PRP is same as that of render parameter, but both portlets should agree that, they support that PRP. For that you need to register the supported PRPs in portlet.xml file of both the portlets. Please refer to this link for more info.This is what the specification insist. Imagine a scenario where in we have multiple portlets from various vendors on a portal page. It is a security concern if one portlet could retrieve the parameters from the URL even if it is not targeted to that portlet.
Another approach (which is not recommended) is to type case the RenderRequest to HttpServletRequest and get the parameter from request. It is not mentioned in the specification that PortletRequest should be a HttpServletRequest. So it is better not to do that. Future implementation of Portal can change this.
Third approach is to use the URL Generation APIs and construct the URL which has the parameters targeting the portlet. You can refer to the below link which has some helper classes. This will simplify your job. Advanced URL Generation Helper Classes
The best way is to use PRP. Both the source portlet and target portlet are loosely coupled.