Fórum
Returning jsp with model from ajax call
Peter Hellstrand, modificado 11 Anos atrás.
Returning jsp with model from ajax call
Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
I am trying to update my gui with ajax. How do I pass objects from my portlet to the jsp.
In Spring i void just do
Now Im doing this but it is so ugly. How do you do this?
In Spring i void just do
@Requestmapping( value= "/ajax/cart")
public ModelAndView getCart(){
ModelAndView mav = new ModelAndView("/cartjsp");
mav.addAttribute("cart", cartService.getCart());
return mav;
}
Now Im doing this but it is so ugly. How do you do this?
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
Cart cart = new Cart();
cart.setTotalUnitCount("99999999999");
TotalPrice t = new TotalPrice();
t.setCurrencyIso("kr");
t.setValue("324234");
cart.setTotalPrice(t);
request.setAttribute("cart", cart);
response.setContentType("text/html");
response.resetBuffer();
response.getWriter().print("<div>");
response.getWriter().print("Current Cart");
response.getWriter().print("<br>");
response.getWriter().print("Nr Items : " + cart.getTotalUnitCount());
response.getWriter().print("<br>");
response.getWriter().print("Price : " + cart.getTotalPrice().getValue());
response.getWriter().print("<br>");
response.getWriter().print("Currency : " + cart.getTotalPrice().getCurrencyIso());
response.getWriter().print("</div>");
}
Peter Hellstrand, modificado 11 Anos atrás.
RE: Returning jsp with model from ajax call
Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
I think i found out
Cart cart = new Cart();
cart.setTotalUnitCount("99999999999");
TotalPrice t = new TotalPrice();
t.setCurrencyIso("kr");
t.setValue("324234");
cart.setTotalPrice(t);
request.setAttribute("cart", cart);
getPortletContext().getRequestDispatcher("/html/store/cart.jsp").include(request, response);