soufan

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  22 随笔 :: 0 文章 :: 0 评论 :: 0 Trackbacks
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();
}
posted on 2006-12-19 16:10 soufan 阅读(362) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: