Foren

Returning jsp with model from ajax call

Peter Hellstrand, geändert vor 11 Jahren.

Returning jsp with model from ajax call

Regular Member Beiträge: 166 Beitrittsdatum: 30.11.11 Neueste Beiträge
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


@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, geändert vor 11 Jahren.

RE: Returning jsp with model from ajax call

Regular Member Beiträge: 166 Beitrittsdatum: 30.11.11 Neueste Beiträge
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);