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 req
I have voted up the above answer but it seems to work OK with RestEasy up to 2.3.2.Final, latest is 2.3.5.Final (for today). It seems to work OK with Jersey bundled with Glassfish 3.1.2.2 too.
This doesn't work with the RestEasy above 2.3.2.Final when I tried. I thought to share this observation as it took me a while to figure out what caused 'java.lang.ClassCastException: $Proxy262 cannot be cast to org.apache.catalina.core.ApplicationHttpRequest'
However I am not trying to dive deep how to solve it, I came across some thoughts https://stackoverflow.com/a/5149950/1398360
Cheers
Using org.jboss.resteasy.resteasy-html
version 3.0.6.Final
you can directly access the HttpServletRequest
and inject your own attributes before directing output to a RESTEasy View
.
@GET
@Path("{eventid}")
@Produces("text/html")
public View getEvent(@Context HttpServletResponse response,
@Context HttpServletRequest request,
@PathParam("eventid") Long eventid){
EventDao eventdao = DaoFactory.getEventDao();
Event event = eventdao.find(eventid);
request.setAttribute("event", event);
return new View("eventView.jsp");
}
This emulates some behavior of the Htmleasy
plugin without having to rewire your web.xml
.
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);
}