さて、JAX-RS メソッドから JSF ページに転送する方法を見つけました。
@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;
}
ここで説明されているように: https://www.java.net//forum/topic/glassfish/glassfish/forwarding-jsf-jax-rs
メソッドによる注入は、フィールドへの注入によっても行うことができます。これは「好み」の問題です。
これは TomEE (Apache CXF) でテストされています。これが単なる汚い「ハック」なのか、それとももっと良い方法があるのか 、少し興味があります。
アップデート
JSFタグを問題なくレンダリングするリダイレクトのより良い方法を見つけました(私の場合、タグなど<p:graphicImage/>
は正しくレンダリングされませんでした)
@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();
}