2012-03-19 15 views
0

私はライン..getRequestDispatcher(」「)の.forwardはJSF 2.0

request.getRequestDispatcher("SomePage.xhtml").forward(request, response); 

があるときに、これまでJSF 2.0

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() 
        .getRequest(); 
      HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); 
...... 

try { 
      request.getRequestDispatcher("SomePage.xhtml").forward(request, response); 
     } catch (ServletException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

を使用している私のアプリでは、次のコードを持っていますが、中には動作しません。実行私は次の例外を取得しています...

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
    at java.util.ArrayList.RangeCheck(ArrayList.java:547) 
    at java.util.ArrayList.get(ArrayList.java:322) 
    at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165) 
    at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1432) 
    at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:265) 
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151) 

は何らかのappilcationのconstaintsに私が

を使用することはできません
FacesContext.getCurrentInstance().getExternalContext().redirect(); 

方法..

が、それはJSF 2.0のバグです?

+0

通常のJSFナビゲーションでフォワードを行うことができたので、フォワードを行う前にJSFライフサイクルメソッドを呼び出す必要があるようです。任意のアイデアの方法? – user1220373

答えて

1

これはJSF2でのナビゲーションの標準的なソリューションではないため、この方法でリダイレクトを送信しようとしたことはありません。

があなたのナビゲーションへ?faces-redirect=trueを取り付け、これは仕事をすべきナビゲーションリンクにリダイレクトコマンドを指定

1:ここでは

はJSF 2.0の環境で正常に動作するいくつかの方法があります。

public String someAction(){ 
    // Logic here 
    return "newPage" + "?faces-redirect=true" 
} 

<h:form id = "form"> 
    <h:inputText>...</h:inputText> 
    <h:commandButton action = "#{controller.someAction}" /> 
</h:form> 

someActionでログインを処理した後、ナビゲーション・フローはnewPage.xhtmlにリダイレクトされます。 UIフォームからアクションを正しく呼び出すだけです。

2.この方法は、あなたが探しているものに近い外部コンテキストを通じて

をリダイレクトを指定します。

+0

転送!=リダイレクト。 – BalusC

+0

@BalusCありがとう!私はそこで '.redirect()'を見て、何とか私を誤解させます – Ionut

0

まず第一に、あなたはJSFの内側javax.servlet.*クラスを使用する必要があるとき変更が大きいと、間違ったやり方や不必要に複雑すぎる変更が発生します。次にimport javax.servlet...;行を追加する必要がある場合は、この点を覚えておいてください。

具体的な問題としては、特定のケースでは、フォワードを実行するためにビューIDを戻すだけです。

public String someAction() { 
    // ... 

    return "SomePage"; 
} 

代替方法はExternalContext#dispatch()ですが、これは不必要に複雑すぎます。