Fórum
Not able to read parameter from friendly url if instanceable is set to true
Not able to read parameter from friendly url if instanceable is set to true
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens RecentesWe are using Liferay 7 and for one of the portlet's we would like to create friendly URLs. I gone through this article and followed steps as mentioned in this article.
web/mycustomsite/eating-right/-/media/view/31712
Above is the example of friendly URL that we are trying to create. One strange thing we have noticed is that if we keep portlet instanceable as true then we are not able to read request parameter from friendly URL and if we keep the instanceable as false then it works as expected.
And yes i have tried all available ways to read the parameter (from RenderRequest and HTTPServletRequest) in case if instanceable is set to true but it does not works.
Below is my friendly-url-route.xml
<!--?xml version="1.0"?-->
<routes>
<route>
<pattern></pattern>
</route>
<route>
<pattern>/view/{articleId:\d+}</pattern>
</route>
</routes>
And this is how i have created my custom FriendlyURLMapper class.
@Component(
property = {
"com.liferay.portlet.friendly-url-routes=META-INF/friendly-url-routes/media-friendly-url-routes.xml",
"javax.portlet.name=com_liferay_portlet_CustomPortlet"
},
service = FriendlyURLMapper.class
)
public class CustomPortletFriendlyURLMapper extends DefaultFriendlyURLMapper {
@Override
public String getMapping() {
return _MAPPING;
}
private static final String _MAPPING = "media";
}
Any pointer on this issue would be appreciated.
Thanks in advance !
Jitendra
RE: Not able to read parameter from friendly url if instanceable is set to
Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens RecentesOne strange thing we have noticed is that if we keep portlet instanceable as true then we are not able to read request parameter from friendly URL and if we keep the instanceable as false then it works as expected.
That makes sense. Did you try adding instanceId in your friendly-url xml, like here: https://github.com/liferay/liferay-portal/blob/master/modules/apps/forms-and-workflow/calendar/calendar-web/src/main/resources/META-INF/friendly-url-routes/routes.xml#L10
Thanks.
RE: Not able to read parameter from friendly url if instanceable is set to
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens RecentesI tried by adding instanceId in friendly url mapping.xml but still it is not working.
<routes>
<route>
<pattern>{instanceId}/view/{articleId:\d+}</pattern>
</route>
<route>
<pattern>{instanceId}/next/{index:\d+}</pattern>
</route>
</routes>
I also tried by adding instance id in url like below but still it is not working.
web/mycustomsite/eating-right/-/media/Oejukt5Ckz5d/view/31712
While debugging DefaultFriendlyURLMapper class i found that if we add instanceid in pattern then it is not able to find the route. Below check for URL pattern is not getting full filled.
i
f (!router.urlToParameters(friendlyURLPath, routeParameters)) {
if (_log.isWarnEnabled()) {
_log.warn(
"No route could be found to match URL " + friendlyURLPath);
}
return;
}
Thanks !
RE: Not able to read parameter from friendly url if instanceable is set to
Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens RecentesHow are you generating those URL?
Thanks.
RE: Not able to read parameter from friendly url if instanceable is set to
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens RecentesWe are generating URL like this.
<%
String portletURL = PortalUtil.getLayoutFriendlyURL(themeDisplay.getLayout(), themeDisplay) + "/-/media/view/";
%>
<a href="<%=portletURL%>${mediaBean.articleId}"><img align="left" src="${mediaBean.imageUrl}"></a>
P.S - I know we could have used PortletURL API's or tags to generate URL but as we had to generate URL for lots of content so we thought to generate manually as above.
Thanks !
RE: Not able to read parameter from friendly url if instanceable is set to
Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
P.S - I know we could have used PortletURL API's or tags to generate URL but as we had to generate URL for lots of content so we thought to generate manually as above.
Thanks !
Usually when testing possible bugs or just things that aren't working is good to make tests as simplest as possible.
Please first create URL using PortletURL as it should be done, or just use a link in jsp using portletURL tag, then click on it, so we can discard options.
Thanks.
RE: Not able to read parameter from friendly url if instanceable is set to
Regular Member Postagens: 127 Data de Entrada: 16/09/19 Postagens RecentesHi All,
I am facing similar issue where I am unable to read the parameter from friendly URL.
I am trying to read the parameter in my render method which extends MVCRenderCommand .
but no luck.
Friendly URL: http://localhost:8080/group/guest/kht/-/lpscall/102?
route.xml :
<route>
<pattern>/{leaveId:\d+}</pattern>
<generated-parameter
name="leaveId">{leaveId}</generated-parameter>
<implicit-parameter
name="mvcRenderCommandName">linkeService</implicit-parameter>
<implicit-parameter
name="p_p_lifecycle">0</implicit-parameter>
<implicit-parameter
name="p_p_state">normal</implicit-parameter>
<implicit-parameter
name="tag"></implicit-parameter>
</route>
in render method I use the below ways :
long leaveId = ParamUtil.getLong(renderRequest, "leaveId",0);
and
GetterUtil.getString(renderRequest.getAttribute("leaveId"))
I require leaveId value in my render method which is 102 in friendly URL.
Regards,
Enayath