How to change destination JSP from within RENDER_RESPONSE phase?
public void
beforePhase
(
PhaseEvent arg0
)
{
if
(
arg0.getPhaseId
()
== PhaseId.RENDER_RESPONSE
)
{
FacesContext facesContext = arg0.getFacesContext
()
;
ViewHandler vh = facesContext.getApplication
()
.getViewHandler
()
;
UIViewRoot newRoot = vh.createView
(
facesContext,
"/yourNew.jsp"
)
;
facesContext.setViewRoot
(
newRoot
)
;
}
How to foward to another JSP from an actionListener ActionEvent
有两种方法:
简单的方法是在commandlink中添加一个 action attribute .然后你有一个actionListener 和 an action Attribute, 两个都是可行的.
但是你还可以使用下面的代码:
String viewId = "/edit.jsp"; FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot view = context.getApplication().getViewHandler().createView(context, viewId); view.setViewId(viewId); context.setViewRoot(view); context.renderResponse();
如何从java代码中重定向一个JSF页面示例代码如下:
public static void redirectPage(String szPage) { FacesContext context = FacesContext.getCurrentInstance(); javax.faces.application.Application app = context.getApplication(); UIViewRoot view = app.getViewHandler().createView(context, szPage); context.setViewRoot(view); context.renderResponse(); } |
|