0

私はこのようなものを持っています:

<h:commandButton value="test" action="#{bean.action}"/>

アクション メソッドが評価されたら、(場合によってのみ) 絶対 URL に移動したいと考えています。

「bean.action」がコンテキスト内の有効なパスに対応する相対パスを返す場合、そこに移動することはわかっていますが、それは望ましくありません。

アクションのリターンを評価したいのですが、問題がなければ「www.anypage.com」のような絶対 URL に移動します。

<a href="www.anypage.com">test</a>

しかし、アクションリターンに応じて、jsf2 の利点を維持します。

何か案は?ありがとう

4

1 に答える 1

2

簡単ExternalContext.redirect()です。アクション メソッドで使用するだけです。

public String action() {
    doYourProcessing();
    if(/*some condition*/) {
        FacesContext.getCurrentInstance().getExternalContext().redirect(/*absolute path*/);
    } else {
        //return a navigation case outcome or null for a postback
    }
}
于 2013-02-20T13:18:47.907 に答える