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 ) ;
}
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中添加一個(gè) action attribute? .然后你有一個(gè)actionListener?和 an action Attribute, 兩個(gè)都是可行的.
但是你還可以使用下面的代碼:
String?viewId?=?"/edit.jsp"; 如何從java代碼中重定向一個(gè)JSF頁面示例代碼如下:
|