Fórum

Not able to read parameter from friendly url if instanceable is set to true

thumbnail
Jitendra Rajput, modificado 7 Anos atrás.

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 Recentes
Hi ,

We 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
thumbnail
Juan Gonzalez, modificado 7 Anos atrás.

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
Hi Jitendra.

Jitendra Rajput:
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.


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.
thumbnail
Jitendra Rajput, modificado 7 Anos atrás.

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 Recentes
Hi Juan,

I 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 !
thumbnail
Juan Gonzalez, modificado 7 Anos atrás.

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
Hi Jitendra.

How are you generating those URL?

Thanks.
thumbnail
Jitendra Rajput, modificado 7 Anos atrás.

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 Recentes
Hi Juan,

We are generating URL like this.



&lt;%
	String portletURL = PortalUtil.getLayoutFriendlyURL(themeDisplay.getLayout(), themeDisplay) + "/-/media/view/";
%&gt;


<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 !
thumbnail
Juan Gonzalez, modificado 7 Anos atrás.

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
Jitendra Rajput:

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.
Anonymous Anonymous, modificado 5 Anos atrás.

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 Recentes

Hi 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