Hi All,
Liferay comes with Friendly URL which reduce unwanted parameter in URL and display small and good URL compare to action and render URL.
Now suppose you want to display News for Mobile device and you want to create friendly URL related it and you want also one action method with this friendly URL. So please follow steps.
1. open your liferay-porltet.xml file of your portlet and write below line after <icon></icon> tag.
<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly- url-mapper-class>
<friendly-url-mapping>mobile</friendly-url-mapping>
<friendly-url-routes>com/portal/mobile-routes.xml</friendly-url-routes>
2. Now create mobile-routes.xml in relevant path in your portlet.
3. Open mobile-routes.xml file and add below content.
Liferay comes with Friendly URL which reduce unwanted parameter in URL and display small and good URL compare to action and render URL.
Now suppose you want to display News for Mobile device and you want to create friendly URL related it and you want also one action method with this friendly URL. So please follow steps.
1. open your liferay-porltet.xml file of your portlet and write below line after <icon></icon> tag.
<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly- url-mapper-class>
<friendly-url-mapping>mobile</friendly-url-mapping>
<friendly-url-routes>com/portal/mobile-routes.xml</friendly-url-routes>
2. Now create mobile-routes.xml in relevant path in your portlet.
3. Open mobile-routes.xml file and add below content.
<?xml version="1.0"?>
<!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">
<routes>
<route>
<pattern>/news</pattern>
<ignored-parameter name="p_auth"/>
<implicit-parameter name="p_p_id">abc_WAR_abcportlet</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="p_p_col_id">column-1</implicit-parameter>
<implicit-parameter name="p_p_col_count">1</implicit-parameter>
<implicit-parameter name="_
abc_WAR_abcportlet
_action">showNews</implicit-parameter>
<implicit-parameter name="parameterName">parameterValue</implicit-parameter>
</route>
</route>
</routes>
4. Now open your controller class and write below method to catch action with name "
showNews".
@RenderMapping(params="action=showNews")
public String handleMobileNews(RenderRequest request,RenderResponse response,Model model){
// Your code to handle this Action method.
}
5. When you call http://localhost:8080/web/guest/home/-/mobile/
news then Liferay will look into
mobile-routes.xml file with /news pattern then it will call "showNews" action method of your
controller class and you can write your logic in it..
Its done !!!!!!!!
Please write to me if you want to more infomation on this.
Regards,
Sandip Patel
No comments:
Post a Comment