I>Friendly url when we access jsp pages(rendering from one jsp to another)
II>Friendly Url when we call action url
III> Friendly Url when we call action url passing parameter(Id)
--------------------------------------------------------------------------
Create one liferay plugin project name as per your requirement, in our case it's CrudOperation, and the portlet is Crud in CrudOperation plugin
project.
Step 1 : Paste below code in view.jsp
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%> <%@page import="javax.portlet.PortletURL"%> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects /> <% long blogId = 123; PortletURL addBlog = renderResponse.createRenderURL(); addBlog.setParameter("jspPage", "/html/crud/addBlog.jsp"); PortletURL editBlogURL = renderResponse.createActionURL(); editBlogURL.setParameter("blogId", Long.toString(blogId)); editBlogURL.setParameter(actionRequest.ACTION_NAME, "editBlog"); %> <p style="border:1px solid green;">Friendly Url Implementation.</p> <a href="<%=addBlog.toString()%>">Add Blog</a><br/> <a href="<%=editBlogURL.toString()%>" >Edit Blog</a>
Step 2 : create one jsp page addBlog.jsp and paste below code
<%@page import="javax.portlet.PortletURL"%> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects /> <% PortletURL addBlogActionURL = renderResponse.createActionURL(); addBlogActionURL.setParameter(actionRequest.ACTION_NAME, "addBlog"); %> <h1> Add Blog</h1> <form action="<%=addBlogActionURL.toString()%>" method="POST"> Blog Title<br/> <input type="text" name="<portlet:namespace/>blogTitle" value=""/><br/> Blog Content<br/> <input type="text" name="<portlet:namespace/>blogContent" value=""/><br/> <input type="submit" value="Add Blog"/> </form>
Step 3 : Add below tags with mentioned value liferay-portlet.xml <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class> <friendly-url-mapping>myFriendlyUrl</friendly-url-mapping> <friendly-url-routes>com/test/routes.xml</friendly-url-routes>
<?xml version="1.0"?> <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd"> <liferay-portlet-app> <portlet> <portlet-name>crud</portlet-name> <icon>/icon.png</icon> <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class> <friendly-url-mapping>myFriendlyUrl</friendly-url-mapping> <friendly-url-routes>com/test/routes.xml</friendly-url-routes> <header-portlet-css>/css/main.css</header-portlet-css> <footer-portlet-javascript> /js/main.js </footer-portlet-javascript> <css-class-wrapper>crud-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>Step 4: create one xml file inside /web-inf/src/com/test folder with name routes.xml and paste below code
<?xml version="1.0"?> <!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.2.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_2_0.dtd"> <routes> <!-- Friendly url when we access jsp pages(rendering from one jsp to another) --> <route> <pattern>/page/{jspPageName}</pattern> <generated-parameter name="jspPage">/html/crud/{jspPageName}.jsp</generated-parameter> </route> <!-- Friendly Url when we call action url --> <route> <pattern>/action/{actionName}</pattern> <generated-parameter name="javax.portlet.action">{actionName}</generated-parameter> <ignored-parameter name="p_auth"/> <ignored-parameter name="p_p_id"/> <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> </route> <!-- Friendly Url when we call action url passing parameter(Id)--> <route> <pattern>/action/{actionName}/myblogId/{blogId:\d+}</pattern> <generated-parameter name="javax.portlet.action">{actionName}</generated-parameter> <generated-parameter name="blogId">{blogId}</generated-parameter> <ignored-parameter name="p_auth"/> <ignored-parameter name="p_p_id"/> <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> </route> </routes>Step 5: Paste below code in java class Crud.java
package com.test; import java.io.IOException; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletException; import com.liferay.util.bridges.mvc.MVCPortlet; /** * Portlet implementation class Crud */ public class Crud extends MVCPortlet { public void addBlog(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { System.out.println("inside add blog..."); } public void editBlog(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { System.out.println("inside edit blog..."); } }OutPut:
Default View :
I> Friendly url when we access jsp pages(rendering from one jsp to another)
II> Friendly Url when we call action url
III> Friendly Url when we call action url passing parameter(Id)
0 comments:
Post a Comment