如何使用JSF在Liferay Portal中重定向

时间:2012-12-22 15:44:50

标签: jsf jsf-2 liferay liferay-6

使用jsf在liferay中重定向到portlet中的另一个页面的方法是什么?我一直在通过javascript尝试window.location.href,但它试图重定向页面而不是门户网站。

1 个答案:

答案 0 :(得分:4)

这取决于您要重定向到哪个页面。

  • 重定向到另一个portlet的第一页。

    假设您有portlet1,并且要从portlet1重定向到portlet2。如果portlet2的URL是http:/ yourDomain / web / portal / portlet2 ,那么下面的代码将从portlet1重定向到portlet2的第一页

    FacesContext context = FacesContext.getCurrentInstance(); javax.faces.context.ExternalContext externalContext = context.getExternalContext(); externalContext.redirect("/web/portal/portlet2");

以上代码将点击portlet2并根据您的欢迎页面配置(在phaselistenerportlet.xml中显示您的第一页。

  • 从Portlet1重定向到Portlet2的其他页面(而不是欢迎页面)。

假设您想从Portlet1重定向到Portlet2的第3页。在这种情况下,使用上面的代码,您可以点击Portlet2。这将调用PhaseListenter。在这里,您可以查看要重定向到的页面,并相应地使用以下代码。

if(someConditionIsMet)
{   
 FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot newPage = context.getApplication().getViewHandler().createView(context,"/your3rdPage.jsf");
 context.setViewRoot(newPage);
context.renderResponse();
}  
  • 重定向到同一Portlet中的某个页面

我认为你不是在寻找这个案子的答案。不过,我认为我对你的问题并不十分清楚。

假设您正在通过h:commandLinkh:commandButton调用链接。并且您正在调用一个方法(返回String)。然后可以使用下面的代码。

public String someMethod()
{
 //Do your checks here
return "success";
  }

必须在faces-config.xml文件中进行配置。

<navigation-rule>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/yourRequiredPage.jsf</to-view-id>
  </navigation-case>
</navigation-rule>