Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Juan M. Gomez
Portlet FriendlyURL not being generated correctly [RESOLVED]
April 16, 2012 3:16 PM
Answer

Juan M. Gomez

Rank: Junior Member

Posts: 69

Join Date: November 7, 2007

Recent Posts

Hi all,

I´m experiencing a strange behavior while using FriendlyURL mapping, I'm trying to map 2 parameters into the friendly url but the second one is never being mapped.

My liferay-portlet.xml:
 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.0.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd">
 3<liferay-portlet-app>
 4  <portlet>
 5    <portlet-name>CalendarView</portlet-name>
 6    <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
 7    <friendly-url-mapping>cal</friendly-url-mapping>
 8    <friendly-url-routes>com/calendar/portlet/urlmapping/calendar-friendly-url-routes.xml</friendly-url-routes>
 9    <instanceable>false</instanceable>
10  </portlet>
11  <role-mapper>
12    <role-name>administrator</role-name>
13    <role-link>Administrator</role-link>
14  </role-mapper>
15  <role-mapper>
16    <role-name>guest</role-name>
17    <role-link>Guest</role-link>
18  </role-mapper>
19  <role-mapper>
20    <role-name>power-user</role-name>
21    <role-link>Power User</role-link>
22  </role-mapper>
23  <role-mapper>
24    <role-name>user</role-name>
25    <role-link>User</role-link>
26  </role-mapper>
27</liferay-portlet-app>


My friendly-url-routes.xml:
 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.0.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_0_0.dtd">
 3<routes>
 4   <route>
 5        <pattern>/date/{date:\d+}</pattern>
 6        <generated-parameter name="date">{date}</generated-parameter>
 7    </route>
 8   
 9   <route>
10        <pattern>/date/{date:\d+}/{category}</pattern>
11        <generated-parameter name="date">{date}</generated-parameter>
12        <generated-parameter name="category">{category}</generated-parameter>
13    </route>
14</routes>


My portlet.jsp:
 1<div>
 2        Parameters: DATE: <%= ParamUtil.getString(renderRequest, "date", "") %>, CATEGORY: <%= ParamUtil.getString(renderRequest, "category", "") %>.
 3</div>
 4
 5<%
 6            PortletURL dayNavigation = renderResponse.createRenderURL();
 7            dayNavigation.setParameter("date", "20120413");
 8
 9            PortletURL dayCategoryNavigation = renderResponse.createRenderURL();
10            dayCategoryNavigation.setParameter("date", "20120413");
11            dayCategoryNavigation.setParameter("category", "category1");
12%>
13
14<a href="<%= dayNavigation.toString() %>">Day Navigation</a>
15<br />
16<a href="<%= dayCategoryNavigation.toString() %>">Day/Category Navigation</a>


The first URL is getting mapped as "http://server/calendar/-/cal/date/20120413",
but the second is resulting in "http://server/calendar/-/cal/date/20120413?_CalendarView_WAR_Calendar_category=category1".

However, if i manually enter the url "http://server/calendar/-/cal/date/20120413/category1" (the one i expect from the second link), both parameters get resolved, so the mapper is working in that way..

What can I be doing wrong? I appreciate any comments.

Juan M.
Jelmer Kuperus
RE: Portlet FriendlyURL not being generated correctly
April 14, 2012 7:17 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

You shouldn't need to add those generated-parameter sections. They are only needed if you take the input of a parameter defined in the url and need to transform it to something else iirc

try removing them and see what happens.

If it still fails try chaning the order of definitions in your route file
Juan M. Gomez
RE: Portlet FriendlyURL not being generated correctly
April 16, 2012 7:23 AM
Answer

Juan M. Gomez

Rank: Junior Member

Posts: 69

Join Date: November 7, 2007

Recent Posts

I haven't undestood completely about generated parameters emoticon..

I removed that sections of the routes.xml but the urls are the same as before. However, I changed the order as you suggested and now works as expected..

The final routes:
1<route>
2        <pattern>/date/{date:\d+}/{category}</pattern>
3    </route>
4   
5    <route>
6        <pattern>/date/{date:\d+}</pattern>
7    </route>


Thanks for the help, it is safe to infer that you must construct the patterns in the routes.xml from more to least parameters?

Juan M.
Jelmer Kuperus
RE: Portlet FriendlyURL not being generated correctly
April 16, 2012 2:51 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

As i recall it moves fhrough them in order and uses the first one that matches. since you provided a date parameter the first rule matched and it did not try to go for the second rule
Juan M. Gomez
RE: Portlet FriendlyURL not being generated correctly [RESOLVED]
April 16, 2012 3:15 PM
Answer

Juan M. Gomez

Rank: Junior Member

Posts: 69

Join Date: November 7, 2007

Recent Posts

Great!!

Thanks for the help, I´m editing the topic so it appears as resolved emoticon

Juan M. Gómez