RESTeasy and Returning to a JSP page with a model

Loomer picture Loomer · Nov 5, 2010 · Viewed 13.7k times · Source

Is there an easy, not using spring, way to have RESTeasy return a jsp or html page with a model? I want to do something similar to the spring ModelAndView where I have a request to say /contacts/loomer and have it return a mocked up object in a jsp template. All of the examples I see are for JSON/XML. I know in Jersey you can use the viewable, but I need to use only RESTeasy stuff.

Thanks!

I want something like this (but without the spring modelandview):

   @POST
   @PUT
   @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
   @Produces(MediaType.TEXT_HTML)
   public ModelAndView saveContactForm(@Form Contact contact)
         throws URISyntaxException
   {
      service.save(contact);
      return viewAll();
   }

Answer

Loomer picture Loomer · Nov 7, 2010

Okay, I figured it out for anyone who is interested. It was actually fairly trivial once I found an example.

@GET
@Path("{eventid}")
@Produces("text/html")
public void getEvent(@Context HttpServletResponse response,
        @Context HttpServletRequest request,
        @PathParam("eventid") Long eventid) throws ServletException,
        IOException {

    EventDao eventdao = DaoFactory.getEventDao();
    Event event = eventdao.find(eventid);

    request.setAttribute("event", event);
    request.getRequestDispatcher("eventView.jsp").forward(request, response);

    }