Well, I found a way to forward from the JAX-RS method to the JSF page:
@GET @Path("/test") @Produces("text/html") public Response test(@Context ServletContext context, @Context HttpServletRequest request, @Context HttpServletResponse response) { try { String myJsfPage = "/response.xhtml"; context.getRequestDispatcher(myJsfPage).forward(request, response); } catch (ServletException | IOException ex) { return Response.status(NOT_FOUND).build(); } return null; }
As described here: https://www.java.net//forum/topic/glassfish/glassfish/forwarding-jsf-jax-rs
Injection through the method can also be performed by injection in the fields, which is a matter of "preference"
This has been tested in TomEE (Apache CXF). I'm just a little curious if this is just a dirty โhackโ or if there is a better way to do this.
UPDATE
I found a better redirect method that displays JSF tags without any problems (in my case, tags like <p:graphicImage/> did not display properly)
@GET @Path("/test") @Produces("text/html") public Response test(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException { String myJsfPage = "/response.xhtml"; String contextPath = request.getContextPath(); response.sendRedirect(contextPath + myJsfPage); return Response.status(Status.ACCEPTED).build(); }
Sergio
source share