Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Creating urls programmatically
Hi,
Liferay 7.x Newbie here.
Server set up: ok.
Apache reverse proxy: ok.
First Portlet programming and debug: ok.
URLs: not so much.
Hi there, I'm trying to setup a POC to my company and one of the tasks is integrating with legacy systems.
I was able to create a portlet that consumes a URL with a json, produce a list that takes the user to a detail page and show the detail in another portlet programmed by me, as well.
I generate the list of URLs, in the JSP, with:
<c:forEach items="${items}" var="item">
<liferay-portlet:renderURL
plid="16"
portletName="com_example_company_DetailPortlet"
var="genUrl">
<liferay-portlet:param name="numID" value="${item.numID}" />
</liferay-portlet:renderURL>
<a href="${genUrl}">${item.name} </a>
</c:forEach>
That works fine, but.... I would like to use a variable in the plid attribute.
Using a variable construct like ${plidVar}, does nothing, and the correct page is not used in the redered url, defaulting to home instead.
Using <%= plidVar %> is even worse, with a straight exception on type casting....
So, my doubts are:
It is an expected behavior and I need to seek other ways to doit?
There are any other ways to construct urls to other pages?
I feel myself as THE NOOB asking basic questions, but all the articles and threads in the internet that deal with creating urls, are from previous versions, or just use the technique above.
Any input or insight would be very welcome!
Cheers,
Fábio Coelho
Liferay 7.x Newbie here.
Server set up: ok.
Apache reverse proxy: ok.
First Portlet programming and debug: ok.
URLs: not so much.
Hi there, I'm trying to setup a POC to my company and one of the tasks is integrating with legacy systems.
I was able to create a portlet that consumes a URL with a json, produce a list that takes the user to a detail page and show the detail in another portlet programmed by me, as well.
I generate the list of URLs, in the JSP, with:
<c:forEach items="${items}" var="item">
<liferay-portlet:renderURL
plid="16"
portletName="com_example_company_DetailPortlet"
var="genUrl">
<liferay-portlet:param name="numID" value="${item.numID}" />
</liferay-portlet:renderURL>
<a href="${genUrl}">${item.name} </a>
</c:forEach>
That works fine, but.... I would like to use a variable in the plid attribute.
Using a variable construct like ${plidVar}, does nothing, and the correct page is not used in the redered url, defaulting to home instead.
Using <%= plidVar %> is even worse, with a straight exception on type casting....
So, my doubts are:
It is an expected behavior and I need to seek other ways to doit?
There are any other ways to construct urls to other pages?
I feel myself as THE NOOB asking basic questions, but all the articles and threads in the internet that deal with creating urls, are from previous versions, or just use the technique above.
Any input or insight would be very welcome!
Cheers,
Fábio Coelho
Using a variable construct like ${plidVar}, does nothing, and the correct page is not used in the rendered url, defaulting to home instead. Using <%= plidVar %> is even worse, with a straight exception on type casting...
Double-checking. What type is plidVar?
When looking into it, I noticed that the auto-generated taglib documentation is wrong, because it claims that plid is a String, but basically every use of liferay-portlet:renderURL in the Liferay code (along with the implementation of RenderURLTag, which delegates the call to setPlid to ActionURLTag) requires that it be a long.
Double-checking. What type is plidVar?
When looking into it, I noticed that the auto-generated taglib documentation is wrong, because it claims that plid is a String, but basically every use of liferay-portlet:renderURL in the Liferay code (along with the implementation of RenderURLTag, which delegates the call to setPlid to ActionURLTag) requires that it be a long.
Unfortunately wasn't the case. I've some other variations as well and none of then worked.
But hey, thanks for the tip!
But hey, thanks for the tip!
Unfortunately wasn't the case. I've some other variations as well and none of then worked.
Have you tried calling PortletURLFactoryUtil directly?
Have you tried calling PortletURLFactoryUtil directly?
Well, I tried some code from other posts, but all the code were for a different version, or the classes for getting the original request or the plid, weren't available.
Probably there is a method or property that I can consult, but until now, I couldn't figure out.
For example:
Doesn't resolve the
So, I couldn't find a single example that could work in the portlet class to generate urls, that would work in 7.x. Sometimes people throws a line of code or three, like those above, without indicating the context, and that is it. If I had a single example on creating urls inside a portlet method, I would be very happy!
Maybe its just not that common people using such strategy, and maybe I should change my approach on how to tackle the solution.
I don't know where to go, so I'm reading the javadocs, slowly, eventually I'll find the right Classes and methods...
Probably there is a method or property that I can consult, but until now, I couldn't figure out.
For example:
ExternalContext extcontext = FacesContext.getCurrentInstance().getExternalContext();PortletRequest portletRequest = (PortletRequest) extcontext.getRequest();HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(portletRequest));Doesn't resolve the
ExternalContext class, maybe another version, as well?So, I couldn't find a single example that could work in the portlet class to generate urls, that would work in 7.x. Sometimes people throws a line of code or three, like those above, without indicating the context, and that is it. If I had a single example on creating urls inside a portlet method, I would be very happy!
Maybe its just not that common people using such strategy, and maybe I should change my approach on how to tackle the solution.
I don't know where to go, so I'm reading the javadocs, slowly, eventually I'll find the right Classes and methods...
So, I couldn't find a single example that could work in the portlet class to generate urls, that would work in 7.x.
Inside of a .jsp, there is a request object that's provided directly to the .jsp itself (since it's a servlet), so you could just use that? Not sure why you're trying to fetch it from somewhere else.
As asked earlier, have you already tried using PortletURLFactoryUtil? There is an example of it in contacts-web, which is the Contacts portlet, and the only thing it really needs is the import (the class lives in portal-kernel, which is part of the system bundle).
Inside of a .jsp, there is a request object that's provided directly to the .jsp itself (since it's a servlet), so you could just use that? Not sure why you're trying to fetch it from somewhere else.
As asked earlier, have you already tried using PortletURLFactoryUtil? There is an example of it in contacts-web, which is the Contacts portlet, and the only thing it really needs is the import (the class lives in portal-kernel, which is part of the system bundle).
Thank you so much Mr Dang! That is exactly what I looking for. Mental note: I need to up my game in the search task!