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(); } |
|