1 package org
.argeo
.slc
.web
.mvc
;
5 import javax
.servlet
.http
.HttpServletRequest
;
6 import javax
.servlet
.http
.HttpServletResponse
;
8 import org
.springframework
.web
.servlet
.view
.AbstractView
;
10 /** Marshal one of the object of the map to the output. */
11 public class JsonView
extends AbstractView
{
12 private String modelKey
= null;
18 @SuppressWarnings(value
= { "unchecked" })
19 protected void renderMergedOutputModel(Map model
,
20 HttpServletRequest request
, HttpServletResponse response
)
23 if (modelKey
!= null) {
24 if (!model
.containsKey(modelKey
))
25 throw new SlcException("Key " + modelKey
26 + " not found in model.");
27 answer
= model
.get(modelKey
);
29 if (model
.size() != 1)
30 throw new SlcException(
31 "Model has a size different from 1. Specify a modelKey.");
32 answer
= model
.values().iterator().next();
35 if (answer
instanceof JSONObject
) {
36 ((JSONObject
) answer
).write(response
.getWriter());
38 JSONObject jsonObject
= new JSONObject(answer
);
39 jsonObject
.write(response
.getWriter());
43 public void setModelKey(String modelKey
) {
44 this.modelKey
= modelKey
;