あなたは違法なURLを構築しよう - 断片(#
)が常にURLの最後の部分です。
return "view?faces-redirect=true#msg"
が正しいURLになります。
残念ながら、このフラグメントは、少なくともJSF 2.2ではデフォルトのNavigationHandler
で取り除かれています。
BalusCの2つのオプションも同様に機能しますが、私には3番目のオプションがあります。小さなパッチでNavigationHandler
とViewHandler
をラップ:
public class MyViewHandler extends ViewHandlerWrapper {
public static final String REDIRECT_FRAGMENT_ATTRIBUTE = MyViewHandler.class.getSimpleName() + ".redirect.fragment";
// ... Constructor and getter snipped ...
public String getRedirectURL(final FacesContext context, final String viewId, final Map<String, List<String>> parameters, final boolean includeViewParams) {
final String redirectURL = super.getRedirectURL(context, viewId, removeNulls(parameters), includeViewParams);
final Object fragment = context.getAttributes().get(REDIRECT_FRAGMENT_ATTRIBUTE);
return fragment == null ? redirectURL : redirectURL + fragment;
}
}
public class MyNavigationHandler extends ConfigurableNavigationHandlerWrapper {
// ... Constructor and getter snipped ...
public void handleNavigation(final FacesContext context, final String fromAction, final String outcome) {
super.handleNavigation(context, fromAction,
storeFragment(context, outcome));
}
public void handleNavigation(final FacesContext context, final String fromAction, final String outcome, final String toFlowDocumentId) {
super.handleNavigation(context, fromAction,
storeFragment(context, outcome), toFlowDocumentId);
}
private static String storeFragment(final FacesContext context, final String outcome) {
if (outcome != null) {
final int hash = outcome.lastIndexOf('#');
if (hash >= 0 && hash + 1 < outcome.length() && outcome.charAt(hash + 1) != '{') {
context.getAttributes().put(MyViewHandler.REDIRECT_FRAGMENT_ATTRIBUTE, outcome.substring(hash));
return outcome.substring(0, hash);
}
}
return outcome;
}
}
良い考えJSのその部分(私は理由JAVASERVERFACES-3154の修正のため、とにかくのViewHandlerのラッパーを作成する必要がありました)。また、 'ExternalContext#redirect()'も大きく動いています。もう一度、素敵な答え:) – bluefoot