Reputation: 61
Can anyone please help me how to integrate OpenCMS with a Java Spring Web Application.Already googled and gone thru a lot of websites but no use.So, please help me.
Upvotes: 4
Views: 3004
Reputation: 14551
Add a REST-API to your Spring-application and fetch data from OpenCms jsps directly through that API.
Here an example how to fetch data using Jackson to convert JSON to Objects:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ page import="org.codehaus.jackson.map.ObjectMapper" %>
<%@ page import="org.codehaus.jackson.type.TypeReference" %>
<%@ page import="java.util.*, java.net.*" %>
<%
ObjectMapper mapper = new ObjectMapper();
List<Map<String, Object>> result = mapper.readValue(new URL("https://server/api/rest/employeesOrderedByDepartment"), new TypeReference<List<Map<String, Object>>>() {} );
pageContext.setAttribute("result", result);
%>
<div class="span10">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Department</th>
<th>Function</th>
<th>Phone & Email</th>
</tr>
</thead>
<tbody id="staffbody">
<c:forEach items="${result}" var="person" varStatus="status">
<tr>
<td>${person.lastName} ${person.firstName}</td>
<td>${person.department.name}</td>
<td>${person.function}</td>
<td>${person.phone}<br /><a href='mailto:${person.email}'>${person.email}</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
Upvotes: 0
Reputation: 1158
I think there are two approaches in integrating SpringMVC with OpenCMS:
1) Two separate applications, a SpringMVC application and a standard OpenCMS installation. The SpringMVC application fetches content from OpenCMS via webservices implemented in OpenCMS. A bit more detail can be found here: http://lists.opencms.org/pipermail/opencms-dev/2012q3/037154.html. This approach is good if you are starting a new project or extending an existing SpringMVC site to add content management. It allows a clean separation between SpringMVC and the content management.
2) Integrating SpringMVC with a standard OpenCMS installation. This means that after the opencms.war is deployed the web.xml is modified to add the SpringMVC dispatcher servlet and a custom view resolver. Controllers are SpringMVC and views are OpenCMS resources. This approach is good if you already have an existing OpenCMS site and want to extend the site to have MVC functionality. For a detailed description of this approach please have a look at http://blog.shinetech.com/2013/04/09/integrating-springmvc-with-opencms/
Upvotes: 4