Skip to content

Instantly share code, notes, and snippets.

@tgrall
Last active December 13, 2015 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgrall/4944142 to your computer and use it in GitHub Desktop.
Save tgrall/4944142 to your computer and use it in GitHub Desktop.
View call for blog on collated views
View view = client.getView("brewery", "all_with_beers");
Query query = new Query();
query.setIncludeDocs(true).setLimit(100);
ViewResponse result = client.query(view, query);
ArrayList<HashMap<String, String>> items =
new ArrayList<HashMap<String, String>>();
for(ViewRow row : result) {
HashMap<String, String> parsedDoc = gson.fromJson(
(String)row.getDocument(), HashMap.class);
HashMap<String, String> item = new HashMap<String, String>();
item.put("id", row.getId());
item.put("name", parsedDoc.get("name"));
item.put("type", parsedDoc.get("type"));
items.add(item);
}
request.setAttribute("items", items);
request.getRequestDispatcher("/WEB-INF/breweries/all.jsp")
.forward(request, response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment