2012-12-22 28 views

回答

2

這取決於您要重定向到哪個頁面。

  • 重定向到另一個portlet的第一頁。

    假設你有portlet1和portlet1要重定向到portlet2。如果portlet2的網址爲http:/ YOURDOMAIN/網站/門戶/ portlet2然後下面的代碼會重定向到portlet2的第一頁從portlet1

    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>