Spring 3.1 Portlet with Liferay 6.1 part 3

Previous Post

Now we will write the JSP and Java Controller with business logics.

JSPs as per folder you may put either inside or outside the /WEB-INF. Here I have mention outside the WEB-INF Below is the structure.

Spring Portlet

JSP createEmployee.jsp is a simple Action form , in which we are taking the Employee Details.

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL var="createEmployeeDetailURL">
	<portlet:param name="action" value="createEmployee" />
<aui:form action="<%=createEmployeeDetailURL %>" method="post" name="createEmp">
		 	<aui:input type="text" name="firstName" label="First Name" />
                        <aui:input type="text" name="LastName" label="Last Name" />
         		<aui:input type="text" name="email" label="Email" />
			<aui:input type="text" name="phoneNo" label="Phone No" />
	        	<aui:button type="submit" value="Save"  />

And when the Action is trigged Its search for the controller and map with the action param createEmployee. Once it land into the method it execute the business logic of the method.

Here is the EmployeeController.java Controller.
Inside the @ActionMapping we are getting all the params valus and setting them into the employee object
[Employee employee = new EmployeeImpl();]

Then we are calling the EmployeeLocalServiceUtil.addEmployee(employee); to add the Employee Details into database.

package com.navin.example.action;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.theme.ThemeDisplay;
import com.navin.example.liferay.model.Employee;
import com.navin.example.liferay.model.impl.EmployeeImpl;
import com.navin.example.liferay.service.EmployeeLocalServiceUtil;

 * Portlet implementation class EmployeeController
 * @author NavinAgarwal
public class EmployeeController {
	public String createEmployee(RenderRequest request,RenderResponse response) {	
		return "createEmployee";    
	@RenderMapping(params = "redirectPage=welcome")
	public String registration(RenderRequest request,RenderResponse response) {
		return "welcome";
	@ActionMapping(params = "action=createEmployee")
	public void createEmployee(ActionRequest request,ActionResponse response)throws SystemException
		ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
		Employee employee = new EmployeeImpl();
		response.setRenderParameter("redirectPage", "welcome");
		request.setAttribute("EmployeeName",request.getParameter("firstName")+" "+request.getParameter("LastName"));



Tagged: ,

One thought on “Spring 3.1 Portlet with Liferay 6.1 part 3

  1. […] Next Page for the JAVA Controller and JSP […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: