Sunday, 9 December 2012

JSTL with Liferay

To configure JSTL Core library with Liferay require following steps

Step 1 : Add jstl-api.jar and jstl-impl.jar into your liferay-plugin-package.properties file
            /WEB-INF/liferay-plugin-package.properties
             or
             copy both these jars into your project - /WEB-INF/lib folder


Step 2 : Include following syntax to JSTL Core library in your JSP:
             <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

e.g        Set attribute in your java class
                      Employee e1 =new Employee(1, "Tanaji", "Mumbai");
                      List<Employee> empList = new ArrayList<Employee>();
                      empList.add(e1);
                      request.setAttribute("employeeList", empList);               

            Now you can use JSTL tag directly in your JSP file like this....
             <c:forEach var="emp" items="${employeeList}" >
                     Employee Name :-> <c:out value="${emp.name}"></c:out>
            </c:forEach>