Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Peter Hellstrand
Returning jsp with model from ajax call
July 29, 2012 5:04 AM
Answer

Peter Hellstrand

Rank: Regular Member

Posts: 167

Join Date: November 30, 2011

Recent Posts

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

 1
 2@Requestmapping( value= "/ajax/cart")
 3public ModelAndView getCart(){
 4
 5   ModelAndView mav = new ModelAndView("/cartjsp");
 6   mav.addAttribute("cart", cartService.getCart());
 7   return mav;
 8
 9}


Now Im doing this but it is so ugly. How do you do this?

 1
 2public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
 3        Cart cart = new Cart();
 4        cart.setTotalUnitCount("99999999999");
 5        TotalPrice t = new TotalPrice();
 6        t.setCurrencyIso("kr");
 7        t.setValue("324234");
 8        cart.setTotalPrice(t);
 9       
10        request.setAttribute("cart", cart);
11        response.setContentType("text/html");
12        response.resetBuffer();
13        response.getWriter().print("<div>");
14        response.getWriter().print("Current Cart");
15        response.getWriter().print("<br/>");
16        response.getWriter().print("Nr Items : " + cart.getTotalUnitCount());
17        response.getWriter().print("<br/>");
18        response.getWriter().print("Price : " + cart.getTotalPrice().getValue());
19        response.getWriter().print("<br/>");
20        response.getWriter().print("Currency : " + cart.getTotalPrice().getCurrencyIso());
21        response.getWriter().print("</div>");
22   
23    }
Peter Hellstrand
RE: Returning jsp with model from ajax call
July 29, 2012 5:52 AM
Answer

Peter Hellstrand

Rank: Regular Member

Posts: 167

Join Date: November 30, 2011

Recent Posts

I think i found out

 1
 2Cart cart = new Cart();
 3cart.setTotalUnitCount("99999999999");
 4TotalPrice t = new TotalPrice();
 5t.setCurrencyIso("kr");
 6t.setValue("324234");
 7cart.setTotalPrice(t);
 8request.setAttribute("cart", cart);
 9getPortletContext().getRequestDispatcher("/html/store/cart.jsp").include(request, response);