liferay 6.x, using friendlyURLMapper for redirection

Szymon Marciniewicz, modified 14 Years ago. New Member Posts: 18 Join Date: 2/13/12 Recent Posts
So I'm working on upgrading Liferay 5.1.4 to 6.0. Obviously previous way of creating URL Mappers is deprecated, so I want to convert my mappers to the ones used in Liferay 6, but I have an issue with this.

My friendly URL Mapper looked like this in Liferay 5.1.4

public class EventDayDetailsFriendlyUrlMapper extends BaseFriendlyURLMapper {

    private static final String MAPPING = "event-schedule"; 
    private static final String PORTLET_ID = "myeventschedule_WAR_portlet";
      
	@Override 
	public String getPortletId() {
		return PORTLET_ID;
	}
 
	public String buildPath(LiferayPortletURL portletUrl) {
		return null;
	}

	public String getMapping() {
 		return MAPPING;
	}

	public void populateParams(final String friendlyUrlPath, final Map<string, string[]> params, Map<string, object> requestContext) {
		addParam(params, "p_p_id", PORTLET_ID);
		addParam(params, "p_p_action", "0");
		addParam(params, "p_p_state", WindowState.NORMAL.toString());
		addParam(params, "p_p_mode", PortletMode.VIEW.toString());
		addParam(params, "p_p_lifecycle", 1);
		addParam(params, "action", "viewEventDay");

	}</string,></string,>


The idea of this friendly URL Mapper was to first redirect to the function in my event controller class which would check if the event exists, and if yes, then if it is a past event or future event. If a past event, then event day schedule doesn't exist any more, and the user would be redirected to general event details, if it's future event, then it would continue to renderDefault() - rendering portlet containing event day details. This is how this function looks like:

	@RequestMapping(params = "action=viewEventDay")
	protected void actionViewEventDay(final ActionRequest request, final ActionResponse response, final Map<string, object> model) throws IOException {
			String eventId = EventDetailUtil.findEvent(request, model, request.getLocale(), inputValidator, eventService); 
			if(StringUtils.isNotEmpty(eventId)){
				Event pastEvent = eventService.getPastEvent(Integer.valueOf(eventId));
				Event currentEvent = eventService.getCurrentEvent(Integer.valueOf(eventId));
				if((null == pastEvent) &amp;&amp; (null == currentEvent)){
					response.sendRedirect(new UrlGenerator(request).getSEOEventsPageUrl());
					LOG.error("Could not redirect to catalog page: ");
				} else if (null != pastEvent) {	
						String locName = pastEvent.getEventLocation(true);
						response.sendRedirect(new UrlGenerator(request).getSeoEventDetailsUrl(locName, eventId));
				}
			} 
	}</string,>


Basically, from my routes.xml I want to get to the above function, but I have some troubles with that. I'm quite new to liferay, so please help me.

This is how my routes.xml looks like:

<!--?xml version="1.0"?-->

<routes>
	<route>
		<pattern>/event-schedule?eventId={eventId:\d+}</pattern>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
		<implicit-parameter name="javax.portlet.action">viewEventDay</implicit-parameter>
	</route>
</routes>


What am I doing wrong?