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.
-
Take a look at my answer for: http://stackoverflow.com/questions/13490509/what-java-based-cms-can-manage-existing-pages-content – Mathias Conradt Feb 22 '13 at 07:19
-
@Mathias Conradt links in your answer do not work. – Slava Babin Oct 09 '16 at 13:17
-
@SlavaBabin Yes, they don't exist anymore but there are no newer links. I think the file share services have invalidated them over the years. – Mathias Conradt Oct 10 '16 at 04:26
-
@Mathias Conradt I think you could use GitHub if you wanted to have them been available – Slava Babin Oct 10 '16 at 05:48
2 Answers
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/

- 1,080
- 10
- 19
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>

- 13,807
- 14
- 91
- 127