Jooby MVC - How to redirect?

48 views
Skip to first unread message

niko...@brightminds.org

unread,
Apr 25, 2021, 4:54:18 AM4/25/21
to jooby-project
Hello,

Jooby is an awesome Java micro framework.  Developing apps with it is amazing!

I have the following code below.  If someone goes to /shop/order manually then their cart will be 0 in which case I want to redirect them back to the cart vs. letting them through.  Problem is I cannot see how MVC could redirect the URI.  Any ideas?

Thanks in advance!

--Nikolaos

@GET
@Path("/shop/order")
public ModelAndView renderOrder(Context ctx) {
ModelAndView mvc = new ModelAndView("web/shop-order.hbs");
this.setup(mvc, PAGE_ORDER);
mvc.put("showFooter", true);

Cart cart = this.getClientSessionCart(ctx);
//if (cart.getTotal().equals("0")) {
//return ctx.sendRedirect("/shop/cart");      <== What I want to do but does not compile
//}
mvc.put(PAGE_CART_NAME, cart);
return mvc;
}

niko...@brightminds.org

unread,
Apr 25, 2021, 5:03:00 AM4/25/21
to jooby-project
Once again Jooby is smarter than even I expected....

--Nikolaos

Cart cart = this.getClientSessionCart(ctx);
if (cart.getTotal().compareTo(BigDecimal.ZERO) == 0) {
ctx.sendRedirect("/shop/cart");
}
return mvc;



Reply all
Reply to author
Forward
0 new messages