Liferay 7 MVC Render Command Example
Liferay 7 MVC Render Command Example will helps in understanding mvc render command along with code snippet. Let jump into the creation of MVC render command.
Liferay 6 versions uses below approaches to redirect particular JSP page
- MVC Path :
<portlet:renderURL var="viewLeave"> <portlet:param name="backURL" value="<%=currentURL %>" /> <portlet:param name="leaveId" value="${leave.leaveId}" /> <portlet:param name="mvcPath" value="/leave/leaveInfo.jsp"/> </portlet:renderURL>
- custom command:
<portlet:renderURL var="viewLeave"> <portlet:param name="backURL" value="<%=currentURL %>" /> <portlet:param name="leaveId" value="${leave.leaveId}" /> <portlet:param name="cmd" value="leaveInfo"/> </portlet:renderURL>
Please go through the below tutorial to understand Liferay 7 MVC Commands:
Liferay 7 Portlet Commands Example
Liferay 7 Portlet Commands Example tutorial helps developers in creating commands rather writing up all action,resource methods in Portlet controller.READ MORE
Liferay 7 MVC Render Command Tutorail:
- Add javax.portlet.name in LeavePortlet Controller if not there
-
@Component( immediate = true, property = { "com.liferay.portlet.display-category=category.sample", "com.liferay.portlet.instanceable=true", "javax.portlet.display-name=Leave Application", "javax.portlet.name=org_javasavvy_web_leave_portlet", "javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-action=/leave/view", "javax.portlet.init-param.view-template=/leave/view.jsp", "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class ) public class LeavePortlet extends MVCPortlet { }
-
- Create ViewLeaveInfoCmd class to view leave information and make this class as OSGI MVCRenderCommand Service component with below config:
-
@Component( property = { "javax.portlet.name=org_javasavvy_web_leave_portlet", "mvc.command.name=viewleave_info" }, service = MVCRenderCommand.class ) public class ViewLeaveInfoCmd implements MVCRenderCommand{ public final static String VIEW_LEAVE_INFO ="/leave/leaveInfo.jsp"; public final static String ERROR="/leave/error.jsp"; @Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { System.out.println("in ViewLeaveInfoCmd "); try{ long leaveId = ParamUtil.getLong(renderRequest, "leaveId", -1L); }catch(Exception e){ return ERROR; } return VIEW_LEAVE_INFO; } }
-
- In JSP’s, you can access leaveInfo.jsp with below code: add mvcRenderCommandName as init parameter with value “viewleave_info” to load leaveInfo.jsp.
<portlet:renderURL var="viewLeave" > <portlet:param name="backURL" value="<%=currentURL %>" /> <portlet:param name="leaveId" value="${leave.leaveId}" /> <portlet:param name="mvcRenderCommandName" value="viewleave_info"/> </portlet:renderURL>
Access other MVC Command Examples:
Liferay 7 MVCActionCommand Example
Liferay 7 MVCActionCommand Example helps developers in understanding creation of mvc action commands in liferay. Let’s create for a sample action command class for editLeave in leave application. Please go through the below tutorial for understanding…
READ MORE
Liferay 7 MVC Resource Command Example
Liferay 7 MVC Resource Command Example tutorial helps in understanding Liferay 7 resource command. Let’s look into creation of sample resource command class for deleteLeave in leave application. Please go through the below tutorial for…
READ MORE
Comments are closed.