I have a code
@RenderMapping
public ModelAndView model(RenderRequest renderRequest, ModelMap map) {
map.put("form", form);
ModelAndView view = new ModelAndView("view", map);
PortletSession portletSession = renderRequest.getPortletSession(true);
if(portletSession != null) {
MappingJacksonJsonView v = new MappingJacksonJsonView();
view.setView(v);
view.addObject("dataListCustomer", portletSession.getAttribute("listCustomer"));
}
init(renderRequest, view);
return view;
}
I have an error:
java.lang.IllegalArgumentException: application/json is not a supported mime type
at com.liferay.portlet.MimeResponseImpl.setContentType(MimeResponseImpl.java:159)
Error is caused by view.setView(v);
How can I added listCustomer to JSON? In listCustomer I have a ModelMap
I have code:
@ResourceMapping(value="customer")
public ModelAndView customer(
ResourceRequest req,
ResourceResponse res) {
log.debug("List Customer Resource: " + context.getCustomer());
ModelAndView mav = new ModelAndView();
MappingJacksonJsonView v = new MappingJacksonJsonView();
v.setBeanName("ajaxResult");
mav.setView(v);
mav.addObject("customer", context.getCustomer());
return mav;
}
Customer is set in @ActionMapping function and it is OK.
In JSP I have:
<portlet:resourceURL escapeXml="false" id="customer" var="customer"/>
How can I call @ResourceMapping function? Because I don’t see result of log.debug("List Customer Resource: " + context.getCustomer()); in logs.
For ajax (with portal) you cannot use RenderMapping (or ActionMapping), you must use ResourceMapping (and if needed ResourceRequest and ResourceResponse as method parameters).
For example, not using spring but change is trivial, see this SO answer.