Skip to content

Commit

Permalink
JSON data from @ResourceMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed May 6, 2015
1 parent 6723f20 commit e4d38dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -104,6 +104,12 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>

</dependencies>

<build>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/sample/portlet/BooksController.java
Expand Up @@ -35,8 +35,11 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.PortletRequestDataBinder;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import org.springframework.web.portlet.util.PortletUtils;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import sample.domain.Book;
import sample.domain.BookValidator;
Expand Down Expand Up @@ -74,6 +77,14 @@ public String listBooks(Model model) {
return "books";
}

@ResourceMapping("json")
public ModelAndView listBooksJson() {
ModelAndView mav = new ModelAndView();
mav.addObject("books", bookService.getAllBooks());
mav.setView(new MappingJackson2JsonView());
return mav;
}

// view details of a book

@RequestMapping(params="action=viewBook")
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/jsp/books.jsp
Expand Up @@ -29,6 +29,8 @@
<th></th>
</tr>

<a href="<portlet:resourceURL id="json"></portlet:resourceURL>">View JSON</a>

<c:forEach items="${books}" var="book">
<tr>
<td>${book.author}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/include.jsp
Expand Up @@ -20,7 +20,7 @@
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

Expand Down

0 comments on commit e4d38dd

Please sign in to comment.