Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Phu Pham Cong
Please help me create friendly URL in a portlet
June 19, 2012 3:53 AM
Answer

Phu Pham Cong

Rank: New Member

Posts: 16

Join Date: November 30, 2010

Recent Posts

Hi all,

I was tried to create friendly portletUrl follow Adding Friendly URL Mapping to the Portlet
but it does not work. plssss help me.
My code bellow:
in a liferay-portlet.xml
1<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
2        <friendly-url-mapping>publicprofile</friendly-url-mapping>
3        <friendly-url-routes>com/hvn/friendlyurl/publicprofile-friendly-url-routes.xml</friendly-url-routes>
4        <instanceable>false</instanceable>


then in a publicprofile-friendly-url-routes.xml inside com.hvn.friendlyurl package
1<?xml version="1.0"?>
2<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_1_0.dtd">
3<routes>   
4    <route>
5        <pattern>/{jspPageName}</pattern>
6        <generated-parameter name="jspPage">/html/friendlyurl/{jspPageName}.jsp</generated-parameter>
7    </route>   
8</routes>


view.jsp located in /html/friendlyurl
 1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 2
 3<%@ page import="javax.portlet.PortletPreferences" %>
 4
 5<portlet:defineObjects />
 6
 7<%
 8
 9PortletPreferences prefs = renderRequest.getPreferences();
10
11String greeting = (String)prefs.getValue(
12
13    "greeting", "Hello! Welcome to our portal.");
14
15%>
16
17<p><%= greeting %></p>
18
19<portlet:renderURL var="editGreetingURL">
20
21    <portlet:param name="jspPage" value="/html/friendlyurl/publicprofile.jsp" />
22
23</portlet:renderURL>
24
25<p><a href="<%= editGreetingURL %>">Edit greeting</a></p>


then i created publicprofile.jsp located in /html/friendlyurl too
 1<%
 2/**
 3* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
 4*
 5* This library is free software; you can redistribute it and/or modify it under
 6* the terms of the GNU Lesser General Public License as published by the Free
 7* Software Foundation; either version 2.1 of the License, or (at your option)
 8* any later version.
 9*
10* This library is distributed in the hope that it will be useful, but WITHOUT
11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13* details.
14*/
15%>
16<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
17
18<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
19
20<%@ page import="javax.portlet.PortletPreferences" %>
21
22<portlet:defineObjects />
23
24<%
25
26PortletPreferences prefs = renderRequest.getPreferences();
27
28String greeting = renderRequest.getParameter("greeting");
29
30if (greeting != null) {   
31
32    prefs.setValue("greeting", greeting);
33
34    prefs.store();
35
36%>
37
38    <p>Greeting saved successfully!</p>
39
40<%
41
42}
43
44%>
45
46<%
47
48greeting = (String)prefs.getValue(
49
50    "greeting", "Hello! Welcome to our portal.");
51
52%>
53
54<portlet:renderURL var="editGreetingURL">
55
56    <portlet:param name="jspPage" value="/html/friendlyurl/publicprofile.jsp" />
57
58</portlet:renderURL>
59
60<aui:form action="<%= editGreetingURL %>" method="post">
61
62    <aui:input label="greeting" name="greeting" type="text" value="<%= greeting %>" />
63
64    <aui:button type="submit" />
65
66</aui:form>
67
68<portlet:renderURL var="viewGreetingURL">
69
70    <portlet:param name="jspPage" value="/html/friendlyurl/view.jsp" />
71
72</portlet:renderURL>
73
74<p><a href="<%= viewGreetingURL %>">- Back</a></p>


When i click on Edit greeting link to render publicprofiles.jsp page. the link on address bar is: http://localhost:8080/web/guest/friendlyurl/-/publicprofile/publicprofile but it still in current page.
Can anyone help me ?

Sorry for my english emoticon
Tejas Kanani
RE: Please help me create friendly URL in a portlet
June 19, 2012 7:20 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 655

Join Date: January 6, 2009

Recent Posts

Any error in backlog ? Its working fine for me ..
Phu Pham Cong
RE: Please help me create friendly URL in a portlet
June 19, 2012 8:41 PM
Answer

Phu Pham Cong

Rank: New Member

Posts: 16

Join Date: November 30, 2010

Recent Posts

I tried to fix in this morning. It's work fine. I think maybe mistake with naming convention in liferay-portlet.xml or in routes files.
Phu Pham Cong
RE: Please help me create friendly URL in a portlet
June 20, 2012 2:04 AM
Answer

Phu Pham Cong

Rank: New Member

Posts: 16

Join Date: November 30, 2010

Recent Posts

Hi all,

when I create friendly URL for actionRequest phase. How do I remove p_auth parameter on this url? I was tried to <ignored-parameter name="p_auth"/> but still not work.
current url after making friendly look like: http://localhost:8080/web/guest/friendlyurl/-/demo/10196/action?p_auth=No0itTLv.
any idea ?
Phu Pham Cong
RE: Please help me create friendly URL in a portlet
June 20, 2012 2:23 AM
Answer

Phu Pham Cong

Rank: New Member

Posts: 16

Join Date: November 30, 2010

Recent Posts

i found solutions are:
1portlet.add.default.resource.check.enabled=false
2auth.token.check.enabled=false


it work fine for me.
Ashraf habibi
RE: Please help me create friendly URL in a portlet
December 21, 2012 4:35 AM
Answer

Ashraf habibi

Rank: Junior Member

Posts: 32

Join Date: May 13, 2011

Recent Posts

How you resolve your problem....I am also facing same problem.....
Ashraf habibi
RE: Please help me create friendly URL in a portlet
December 21, 2012 6:39 AM
Answer

Ashraf habibi

Rank: Junior Member

Posts: 32

Join Date: May 13, 2011

Recent Posts

Ashraf habibi:
How you resolve your problem....I am also facing same problem.....


Hi

I am able to fix the problem , I am able to navigate to other page.
But I have to hard code the portletId(p_p_id) in --routes.xml like below
<implicit-parameter name="p_p_id">PaymentGateway_WAR_PaymentGatewayportlet_INSTANCE_8MaO</implicit-parameter>

With this its working fine, but the problem is here I hard code the p_p_id, which will change if you drop this portlet on other place.
When I remove this I am getting below error in the log.
ERROR [DefaultFriendlyURLMapper:252] Either p_p_id or instanceId must be provided for an instanceable portlet

How to pass this value dynamically, so that it will work properly..
Please provide your suggestion.

Thanks
Ashraf
Ashraf habibi
RE: Please help me create friendly URL in a portlet
December 21, 2012 7:20 AM
Answer

Ashraf habibi

Rank: Junior Member

Posts: 32

Join Date: May 13, 2011

Recent Posts

Ashraf habibi:
Ashraf habibi:
How you resolve your problem....I am also facing same problem.....


Hi

I am able to fix the problem , I am able to navigate to other page.
But I have to hard code the portletId(p_p_id) in --routes.xml like below
<implicit-parameter name="p_p_id">PaymentGateway_WAR_PaymentGatewayportlet_INSTANCE_8MaO</implicit-parameter>

With this its working fine, but the problem is here I hard code the p_p_id, which will change if you drop this portlet on other place.
When I remove this I am getting below error in the log.
ERROR [DefaultFriendlyURLMapper:252] Either p_p_id or instanceId must be provided for an instanceable portlet

How to pass this value dynamically, so that it will work properly..
Please provide your suggestion.

Thanks
Ashraf


Hi All

I resolved my above problem.
I made multi instance false <instanceable>false</instanceable>.
Before that I also did false and check it, but whenever I change it to false , my friendlyUrl is not able to generate.
Actually after changing the <instanceable>false</instanceable> value, again we have to drag & drop the portlet, then changes will reflect.

The above way I resolve my problem.

Thanks
Ashraf
Masthan Shaik
RE: Please help me create friendly URL in a portlet
April 29, 2013 5:28 AM
Answer

Masthan Shaik

Rank: New Member

Posts: 1

Join Date: January 30, 2013

Recent Posts

Yes , above solution worked for me as well , I am not sure why we need to put false back emoticon .. Thanks all

Cheers
Masthan
Nabil Bahtat
RE: Please help me create friendly URL in a portlet
April 19, 2016 2:19 PM
Answer

Nabil Bahtat

Rank: New Member

Posts: 13

Join Date: October 10, 2013

Recent Posts

Hi all,
Sory about this strange request, I'm new to liferay and I wanted to use liferay polls portlet and set friendlu url using routes like explained in many wiki and docs resources in internet. Unfortunatly I did not manage to have a clean url.
Can you please help to make a polls-friendly-url-routes.xml file ?

Thanks alot.

Nabil