You might have seen long URLs of links/forms of portlets created by Liferay. These URLs are called Portlet URLs and they are generated dynamically at run time when we place the portlet on the Liferay page.
In this article, we will see how to shorten these URLs in portlet so that it’s more user-friendly. (That’s why we are calling it a friendly URL). In other words, a Friendly URL is the process to make shorter Portlet URLs.
Let’s see how this long URL is created at run-time. For easy understanding, I have created a Spring MVC portlet. You can refer to this blog to create a friendly URL for the Liferay MVC portlet too. This portlet will have one file called Name and one submit button which will submit this name.
I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.
Please refer to my previous blog How to create Spring MVC Porltet to create Spring MVC portlet. Give the project name as ‘friendly-url‘ so that eclipse will append -porltet so that it will look like as below screenshot.
In this article, we will see how to shorten these URLs in portlet so that it’s more user-friendly. (That’s why we are calling it a friendly URL). In other words, a Friendly URL is the process to make shorter Portlet URLs.
Let’s see how this long URL is created at run-time. For easy understanding, I have created a Spring MVC portlet. You can refer to this blog to create a friendly URL for the Liferay MVC portlet too. This portlet will have one file called Name and one submit button which will submit this name.
I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.
Please refer to my previous blog How to create Spring MVC Porltet to create Spring MVC portlet. Give the project name as ‘friendly-url‘ so that eclipse will append -porltet so that it will look like as below screenshot.
I would like to further recommend visiting my blog on How to create Render and Action methods
I have set the controller class name as FriendlyUrlController and the package name is com.opensource.techblog.controller
open FriendlyUrlController.java class and add the following methods so that it will look like the below snippet.
package com.opensource.techblog.controller; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.portlet.bind.annotation.ActionMapping; import org.springframework.web.portlet.bind.annotation.RenderMapping; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.util.ParamUtil; @Controller(value = "FriendlyUrlController") @RequestMapping("VIEW") public class FriendlyUrlController { private static Log log = LogFactoryUtil.getLog(FriendlyUrlController.class); /* * Default Render Method */ @RenderMapping public String handleRenderRequest(RenderRequest request,RenderResponse response,Model model){ return "view"; } @ActionMapping(params = "action=addUserName") public void addUserName(ActionRequest request, ActionResponse response) { String userName=ParamUtil.get(request, "userName", ""); log.info("userName is==>"+userName); } }
Explanation:-
- We have simply added Default Render(handleRenderRequest) method and action (addUserName) method with key “addUserName“.
- In the action method(addUserName) we are getting request parameter userName with the help of Liferay utility class ParamUtil and printing it to console ( by logger) to just make sure whatever we enter username is reaching in the controller.
Now, add the code to view.jsp so that it will look like the below snippet.
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects /> <portlet:actionURL var="userNameUrl"> <portlet:param name="action" value="addUserName"></portlet:param> </portlet:actionURL> <form action="${userNameUrl}" method="post"> Name :- <input type="text" name="userName"><br> <input type="submit"> </form>
Explanation:-
- In view.jsp, we have created portlet:actionURL with param action set to addUserName which is having a matching key with the action method in the controller.
- Then we have created a form with one text box(name) and submit button.
Once this is done then build and deploy the portlet. When we deploy the portlet, it will be looks like below screenshot.
When we observe the form URL in the browser console as per the below screenshot, it will look like
and the URL will be
http://localhost:8081/web/guest/test?p_auth=R9q2yoCH&p_p_id=friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6_action=addUserName
Let us understand what each parameter means in this URL.
Note that each parameter in url is separated by &
- http://localhost:8081 :- is the protocol and host address + port
- /web/guest/test :- There are 3 parts. 1) /Web 2) /guest and 3) /test. /test is a friendly url of Liferay public page test. Since its public page, /web is added. While /guest is a friendly url of guest community.
- p_auth=R9q2yoCH:- is the authentication token generated by Liferay for security purposes and it will be changed on each submit.
- p_p_id :- is portlet Id (friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6 in our case) which will be derived from the name of the portlet (defined in portlet.xml file)
- p_p_lifecycle=1 :- which shows the life cycle phase of current request. Since we are calling the action method,’1‘ denotes that the current request is in action phase. Apart from action phase, the portlet has render, resource, and event phase.
- p_p_state :- denotes Liferay page’s window state. There are 3 possible values 1)Normal 2)Maximize and 3) Minimize. We are currently normal state. You can change the state by clicking Maximize / Minimize button on the right side top bar of the portlet.
- p_p_mode :- shows the mode of the portlet. there are various modes of portlet like view, edit, help, etc. Currently, we are in view mode.
- p_p_col_id :- This is the reference ID of the column in Liferay template. there are various out-of-the-box layout templates available (like one column, two column (30-70), etc). So this parameter will show the id of the column where our portlet resides.
- p_p_col_pos :- This parameter is not present in the URL because we have used a one-column layout. If the layout having more than one column then this parameter will be added to URL. It’s showing the position of the column in which our portlet is placed.
- p_p_col_count:- This parameter shows the no of columns in the current layout. Currently, we have only one.
- [p_p_id]_action :- Any parameter in this URL which is prefixed with portlet Id ( friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6 in our case) is the parameter set by that portlet. In our case we have used action parameter to pick corresponding action method.(we have passed action parameter by <portlet:param name=”action” value=”userName”></portlet:param> )
You might have tired to understand each parameter and its value. Don’t you feel that this URL should be small enough to remember easily? Well because of the limitation of the portal context, the URL will be generated run-time only and there is no direct way to make it shorter.
Friendly URL
Fortunately, Liferay provides a way to achieve this. ( to get a Smaller – user-friendly URL).
Let us see how to achieve this.
create one XML file called friendly-url-router.xml under the package com.opensource.techblog.controller (Its absolutely not required to have the same name and location for this file I have created. You may take any appropriate name and location for that.)and add the following code so that it will look like below snippet.
<?xml version="1.0"?> <!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"> <routes> <route> <pattern>/add</pattern> <implicit-parameter name="p_p_id">friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6</implicit-parameter> <implicit-parameter name="p_p_lifecycle">1</implicit-parameter> <implicit-parameter name="p_p_state">normal</implicit-parameter> <implicit-parameter name="p_p_mode">view</implicit-parameter> <implicit-parameter name="action">addUserName</implicit-parameter> </route> </routes>
An explanation will be a little later in this blog.
In next step, add entries in liferay-portlet.xml file after <icon> element.
In next step, add entries in liferay-portlet.xml file after <icon> element.
<?xml version="1.0"?> <!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"> <liferay-portlet-app> <portlet> <portlet-name>friendly-url</portlet-name> <icon>/icon.png</icon> <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class> <friendly-url-mapping>submit-name</friendly-url-mapping> <friendly-url-routes>com/opensource/techblog/controller/friendly-url-router.xml</friendly-url-routes> <instanceable>true</instanceable> <header-portlet-css>/css/main.css</header-portlet-css> <footer-portlet-javascript>/js/main.js</footer-portlet-javascript> <css-class-wrapper>friendly-url-portlet</css-class-wrapper> </portlet> <role-mapper> <role-name>administrator</role-name> <role-link>Administrator</role-link> </role-mapper> <role-mapper> <role-name>guest</role-name> <role-link>Guest</role-link> </role-mapper> <role-mapper> <role-name>power-user</role-name> <role-link>Power User</role-link> </role-mapper> <role-mapper> <role-name>user</role-name> <role-link>User</role-link> </role-mapper> </liferay-portlet-app>
Explanations:- (For liferay-portlet.xml file)
- We have added 3 elements. 1)friendly-url-mapping-class 2)friendly-url-mapping and 3)friendly-url-routes
- friendly-url-mapping-class is the class that will help us to get a friendly URL. This class is provided by Liferay.
- The value of friendly-url-mapping will be used in the URL. It’s the kind of key that will map the friendly URL with the actual portlet URL on the server side.
- friendly-url-routes will be a path of the XML file that we have defined. This XML file is called a router.
- entry of these elements should be the same order as I have defined and they must be placed just immediately after <icon> element.
Explanations:- (For friendly-url-router.xml file)
- This is a router file and it defines the parameters that were there in the URL if we not implemented friendly URL.
- The first element is <pattern> and it will be used to generate the pattern of friendly URL. We have simply given /add so it will be part of generated friendly URL.
- Rest are implicit variables that were in URL if we have not implemented a friendly URL.
Next, build the portlet and refresh the page where this portlet is placed. This time you will observe the form URL in the browser console as below
http://localhost:8081/web/guest/test/-/submit-name/add?p_auth=R9q2yoCH
Cool…… !!! isn’t it? Now let me explain how it’s done
This URL will be the same as the previous one till /web/guest/test
- Liferay then will add – (dash)
- Next is submit-name which is the same as <friendly-url-mapping> element’s value. It means whatever value we give to this element, will be appended after – (dash) in final friendly URL
- Next to it is /add which is nothing but the pattern value in the router (friendly-url-router.xml) file.
- The last is p_auth parameter. Since we have not defined it in an implicit variable(because it’s dynamic) in router XML, it’s showing explicitly in URL.
Important Notes:-
- In this example we have used an instantiable portlet. Because of this, it’s generating the p_p_id as friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6
- In this p_p_id the last 4 characters are instance key and it will only be generated when we place the portlet on-page. So that they are dynamic
- It means If I place the portlet on the page then let say the instance Id generated is pkd5 and when I remove the portlet from page and again if I place it then this time its not necessary that the same instance Id is generated.
- This creates the problem as you can see that we have given p_p_id in router XML as an implicit parameter.
- So the best practice is that make the portlet non-instantiable (by setting instantiable element false in liferay-portlet.xml file) while generating its friendly URL.
- You also have observed that I have defined the action implicit variable, which is nothing but the corresponding action method key so this URL will
So far we have created one action URL and created a friendly URL for that. But what if we have to create multiple friendly URLs. Let us see how to do it.
I would like to further recommended visiting my blog on How to create Render and Action methods
To explain it better, I am adding 2 render methods in the controller class so that it will look like the below snippet.
package com.opensource.techblog.controller; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.portlet.bind.annotation.ActionMapping; import org.springframework.web.portlet.bind.annotation.RenderMapping; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.util.ParamUtil; @Controller(value = "FriendlyUrlController") @RequestMapping("VIEW") public class FriendlyUrlController { private static Log log = LogFactoryUtil.getLog(FriendlyUrlController.class); /* * Default Render Method */ @RenderMapping public String handleRenderRequest(RenderRequest request,RenderResponse response,Model model){ return "view"; } @ActionMapping(params = "action=addUserName") public void addUserName(ActionRequest request, ActionResponse response) { String userName=ParamUtil.get(request, "userName", ""); log.info("userName is==>"+userName); } @RenderMapping(params ="action=viewUser") public String viewUser(RenderRequest request,RenderResponse response,Model model){ return "viewUser"; } @RenderMapping(params ="action=editUser") public String editUser(RenderRequest request,RenderResponse response,Model model){ return "editUser"; } }
Explanation:-
- I have added 2 render method which will just display different JSP files. These render method will be called based on matching keys( viewUser and editUser)
- We also have to create corresponding JSP (viewUser.jsp and editUser.jsp) at the same path where we have defined view.jsp (inside /WEB-INF/jsp folder)
Next, we will add an entry in router XML as the below snippet.
<?xml version="1.0"?> <!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"> <routes> <route> <pattern>/add</pattern> <implicit-parameter name="p_p_id">friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6</implicit-parameter> <implicit-parameter name="p_p_lifecycle">1</implicit-parameter> <implicit-parameter name="p_p_state">normal</implicit-parameter> <implicit-parameter name="p_p_mode">view</implicit-parameter> <implicit-parameter name="action">addUserName</implicit-parameter> </route> <route> <pattern>/view</pattern> <implicit-parameter name="p_p_id">friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6</implicit-parameter> <implicit-parameter name="p_p_lifecycle">0</implicit-parameter> <implicit-parameter name="p_p_state">normal</implicit-parameter> <implicit-parameter name="p_p_mode">view</implicit-parameter> <implicit-parameter name="action">viewUser</implicit-parameter> </route> <route> <pattern>/edit</pattern> <implicit-parameter name="p_p_id">friendlyurl_WAR_friendlyurlportlet_INSTANCE_dkW6</implicit-parameter> <implicit-parameter name="p_p_lifecycle">0</implicit-parameter> <implicit-parameter name="p_p_state">normal</implicit-parameter> <implicit-parameter name="p_p_mode">view</implicit-parameter> <implicit-parameter name="action">editUser</implicit-parameter> </route> </routes>
Explanation:-
I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.
- Now we have added 2 more entries. one is for view and the second is for edit pattern.
- Note that this time we have defined p_p_lifecycle=0 means it’s for render phase/lifecycle
- Also, we have set the action parameter the same as the key of render methods in the controller.
- This action parameter in this router XML will also be matched with the action parameter while creating render URL in JSP
Next to it add two render URLs and their link to JSP as per the below snippet.
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects /> <portlet:actionURL var="userNameUrl"> <portlet:param name="action" value="addUserName"></portlet:param> </portlet:actionURL> <portlet:renderURL var="viewUserUrl"> <portlet:param name="action" value="viewUser"></portlet:param> </portlet:renderURL> <portlet:renderURL var="editUserUrl"> <portlet:param name="action" value="editUser"></portlet:param> </portlet:renderURL> <form action="${userNameUrl}" method="post"> Name :- <input type="text" name="userName"><br> <a href="${viewUserUrl}">view User</a> <a href="${editUserUrl}">edit User</a> <input type="submit"> </form>
You can observe that I have added 2 more render URLs with action parameters (matched with the key of the render method in the controller and implicit variable in the router XML file.
We can differentiate different friendly URLs by pattern attribute in the router XML file.
Now build the portlet and refresh the page. you will observe the link something like
For /view pattern the url is :- http://localhost:8081/web/guest/test/-/submit-name/view
For /edit pattern the url is :- http://localhost:8081/web/guest/test/-/submit-name/edit
We can differentiate different friendly URLs by pattern attribute in the router XML file.
Now build the portlet and refresh the page. you will observe the link something like
For /view pattern the url is :- http://localhost:8081/web/guest/test/-/submit-name/view
For /edit pattern the url is :- http://localhost:8081/web/guest/test/-/submit-name/edit
Summing Up
- A friendly URL is a technique to make a short portlet URL.
- To make a friendly URL, we need to define router XML for that portlet.
- In this router XML, we can define various parameters (implicit, explicit, etc).
- We can define multiple friendly URLs for the same portlet.
- Additional information can be found at this link.
And that all done. You may do some more practice to get this concept clear. Feel free to ask any questions. I will try my best to answer it.
I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.
Download Source
I need to write friendly URL for blog
present : http://localhost:8080/blogs/-/blogs/accordion?_com_liferay_blogs_web_portlet_BlogsPortlet_redirect=https%3A%2F%2Fmstest.royalsundaram.in%2Fblogs%3Fp_p_id%3Dcom_liferay_blogs_web_portlet_BlogsPortlet%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26_com_liferay_blogs_web_portlet_BlogsPortlet_cur%3D1%26_com_liferay_blogs_web_portlet_BlogsPortlet_delta%3D20#pcuz_message_47223
Expecting : https://localhost:8080/blogs/accordion
this is blog site how can i achieve.
Hi Nilang, Thank you for the helpful article! We have successfully set up friendly URLs, but want to remove the /- DASH from the path. Is this possible?
Hi L Wincester,
Sorry for late response. Actually this is not possible as far as I know.
Hi Nilang,
I am using Spring MVC portlet. I have tried this friendly url and it is working for Action and Render Mappings, but when i tried to do the same for resourceMapping, it is changing the url but not calling that method, calling the default renderMapping in the application. our app had a functionality to print a custom page in a new tab when clicked on that link, so im using window.open (). can you suggest way to call the resourceMapping with the friendly url.
Hi Ravi,
For your requirement, you need to define the DIV under which you need to show the print. Then by using javascript,hide all other div except this print when you click on print button.
Regards
Nilang
Can we use the friendly URL for ResourceMapping in spring portlet as well?
In my case, when i click on link, it should open a print window of the custom screen in a new window. the current logic is doing that but the url is very big and as we are using the print functionality the url is printing in all the print pages. Tried to hide the url but it is hiding the page numbers too(which is important for our client). can you suggest a way to customize the url for resourceMapping
Hi Ravi
You can definatley use friendly url for resource mapping (server resource url)
In you case you suppose to use Action URL with windows state as POP_UP and set it to show specific JSP – only for print. Serve resource url can only be useful to serve any resource like json or PDF. Hope this solve your question.
Regards
Nilang
Hi Nilang,
I am using Spring mvc portlet and friendly url mapping for liferay 6.2 but in my url i am unable to hide mvcPath parameter with render url. If i mention implicit parameter in xml, then it is not redirecting to another jsp.
Can you please help me regarding this.
Hello Kinjal,
You need to give mvc path in router xml as below.
/{jspPage:\S+}/
/html/path/{jspPage}.jsp
You can pass jps name while constructing your url which would be then considered as generated parameter. Try this and let me know if you still face any trouble.
Regards
Nilang
I tried as you suggested and my url is changing but desired jsp page is not rendered.
My code in routes.xml :
/{action}
{action}
{mvcPath}
and in jsp i have :
and in controller :
@RenderMapping(params =”action=addEvents”)
public String addEvents(RenderRequest request,RenderResponse response,Model model){
return “addEvents”;
}
Please suggest if I am missing something.
Hello Kinjal,
Welcome to Techblog. Make sure about following things.
1) put some debug points in your this render mapping method and make sure atleast control goes there.
2) make sure addEvents.jsp file present (double check with spell mistake).
Regards
Nilang
I do not want to display submit-name in URL
means http://localhost:8081/web/guest/test/-/edit
is it possible?
Hi Pradnya,
Welcome to Techblog
‘submit-name’ in my example, is the value of tag defined in liferay-portlet.xml file which I believe used to separate friendly url mapper xml for each different portlet. Just check by removing element and see if that works ? Please let me know the result.
Regards
Nilang
Hi NIlang,
Thanks for the reply.
But after removing it I am getting the url as it was earlies like ppid and all.
Hi Pradnya,
It means its required. I will check it from my end. I assume that you are using 6.2.
Regards
Nilang
Hi Nilang
I was created Friendly URL By following code.
<a href="” >MORE
In My liferay-portlet.xml file I have Configured below properties.
com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper
article
article-url-router.xml
And I have created one file article-url-router.xml and put below configuration.
/view
article_WAR_articleportlet
0
normal
view
viewArticle
the Url is generated below like
http://localhost:8080/web/guest/-/article/view?_article_WAR_articleportlet_articleCategory=CATEGORY&_article_WAR_articleportlet_articleId=12345
In Url Parameter also append.Is there any way to pass the parameter with out appending in URL and i also want to create dynamic Friendly URL like category is entertainment,
http://localhost:8080/web/guest/-/article/view/entertainment
So is this possible,Can you Please help me?
Thanks in Advance
dsd
This comment has been removed by a blog administrator.
Hi Nilang,
Nice one!!.. I have 2 parameters with dynamic data which will be part of the URL.. How do i handle those ??
Hi Nithin,
Its possible to pass dynamic parameter as well. I will write separate blog on the same and let you know.
Regards
Nilang
Hi Nilang,
Just wanted to know, in case of when we are using multiple portlet in a single portlet then will this work ? if yes do i need to create seperate xml’s for every portlet ?
Hi Ravi,
Welcome to Tech blog and thanks for writing. Friendly url will work even if you have multiple portets in single plugin project. If you observe, when WAR is deployed, there will be separate folder created for each portlet in plugin project. (However there will be only one WAR) For different portlet, you no need to create separate xml file but you need to add entry in portlet.xml, liferay-portlet.xml file. You can refer my another blog :- https://www.opensource-techblog.com/2012/12/how-to-create-multiple-portlets-in.html
Let me know if you need any further help.
Regards
Nilang
Hi Nilang,
Thank you for your time.
I have studied it from your blog.But when i am using action URL p_auth is appearing in URL while in render URL , URL is ok as i want to create it .I want to remove it from URL when i am using action URL also
Hi Vasudev,
I will check and let you know the solution.
Regards
Nilang
Hi,
How to remove p_auth from url ???
i have tried it but doesn’t work…please help
Thanks
Hi Vasudev,
Welcome to Tech blog. You can’t directly remove it from url. You can use friendly url instead. Please refer my blog https://www.opensource-techblog.com/2012/11/how-to-create-friendly-url-for-liferay.html for more detail
Hi,
I was able to make friendly url the way you have explained but i need something like host/username …
like creating a profile page with dynamic content .. eg: facebook.com/username …
can we create such url structure in liferay?
Hi Nikhil,
Welcome to Tech blog. In Liferay the friendly url mean for reducing parameters in url. If you observe, if we don’t put the parameter in xml file, they will be visible in URL. So from Liferay point of view, friendly url is concept to reduce parameters appending into URL. In your case, its depend upon what parameters are used while creating render or action URLs. You can also append custom parameters in xml file if they are fixed for that page or portlet. Hope this explanation answers your questions.
Feel free to ask questions / give suggestions.
Regards
Nilang
Hi mate,
Is there any way to contact you on email?
good (Y)
Hi Berguiga,
Thanks for the appreciation and welcome to tech blog. Feel free to ask any questions / give feedback.
Regards
Nilang I Patel
hi,
I am able to make friendly url but some of the process action not working.
Hi Pawan, Thanks for writing it. Can you pls let me know further details what problem you are facing ? I will try my best to help you out.
Regards
Nilang
Hello Nilang,
I have a requirement of creating an actionurl and then sendredirect to another website. When the user clicks a button on third party site, they will append couple of tokens to actionUrl i have sent and call redirect so that it will come into my portlet action.
RenderResponse, ResourceResponse has createActionurl() methods and ActionResponse has sendRedirect(url) method.
How can i make those calls one after another in same method.
Thanks,
Nandi.
Hello Nandi,
Really sorry for late responding. I understand from your problem is that you want the user when press the link, will hit actionurl, and when it reach to page, it should be redirected to some thirdparty website.
This can be achieve by javascript. When the next page (jsp) open you can put redirect to third party website by calling JS function window.url(<>).
Let me know if this work for you.
Regards
Nilang I Patel
Nicely explained and well written, I will def refer your blog to others who want to explore liferay.
Thought of sharing this as I have not found it here.Lifecycle value for resource url is 2.
2
Regards,
Shashant
Hi Shashant,
Welcome to Techblog and thanks for appreciation. Sorry for late responding. Feel free to ask questions / give suggestions.
Regards
Nilang
Hi Nilang,
I need your help. Have you tested your liferay portlets. If yes, what kinda tests have you used.
For my project I am using unit tests and selenium tests. Is it also possible to do any another tests.
Any information would be really helpful for me
Good one Nilang!
Hi Rushikesh,
Thanks for appreciation. Requesting you to give your feedback / Suggestion to make this blog more helpful.
Regards
Nilang
Hi Nilang its very useful post…..
I am having some query when add friendly url for any action it generate me following url
http://localhost:8080/user/test/home/-/submit-name/add?_testportlet_WAR_Testportlet_javax.portlet.action=addUserName
instead of this url
http://localhost:8080/user/test/home/-/submit-name/add
For render phase its working properly.
Hi Tanaji,
It seems that you have to add the parameter action (for addUserName) in router xml like
<implicit-parameter name=”action”>editUser</implicit-parameter>
Try this and let me know if you face any trouble.
Regards
Nilang
I have already made this entry still facing same issue.
Hi Tanaji,
Can you please send me the router xml file to my mail id nilangpatel.techblog@gmail.com ?
Regards
Nilang
I have mail the zip file. Plz check it.
Hi Tanaji,
Can you please do one thing and test it once again.
Just change the p_p_lifecycle to 1 instead of 0. Actually 1 is for Action and 0 is for Render.
Hi Tanaji,
Few updates, I refer your code and created the similar portlet. The change is required in router xml
1) You need to change the DTD version. Because it seems that you are using Liferay 6.1 but the DTD version of router xml is 6.0. You need to change it.
2) instead of action parameter for /add , just try putting javax.portlet.action. I have sent my router xml to you over mail (check your mail).
Just try it and test and let me know if you still having any issues.
You may wonder that for render method why its just work for “action” parameter. but for action url its required javax.portlet.action as actions’ value.
The reason is, for actionUrl, portlet will put the parameter called javax.portlet.action in url. While for renderUrl, there is no such parameter is placed. The reason its showing action parameter in renderurl is you have passed explicetly. You can just remove the action paramtere in renderUrl (in view.jsp) . Also you can remove the action implicite prametere in router.xml
I guess you are confused with SpringMVC porlet and Liferay MVC portetl. Because in my blog I gave example for Spring MVC portlet and you send me the LiferayMVC portlet.
I gave this solution for Liferay MVC porltet only.
Just adding to this comment.
I give this solution for your query is for Liferay MVC portlet only. In my blog, its Spring MVC.