आप एक अवैध यूआरएल बनाने की कोशिश - टुकड़ा (#
) हमेशा एक यूआरएल के अंतिम भाग है।
return "view?faces-redirect=true#msg"
सही यूआरएल होगा।
दुर्भाग्यवश यह खंड डिफ़ॉल्ट NavigationHandler
द्वारा कम से कम जेएसएफ 2.2 में छीन लिया गया है।
जबकि BalusC के दो विकल्प भी काम कर रहे हैं, मेरे पास ऑफ़र करने का तीसरा विकल्प है। एक छोटे पैच के साथ 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;
}
}
स्रोत
2017-06-30 09:55:32
अच्छा सोचा कि जे एस का टुकड़ा (मैं JAVASERVERFACES-3154 के लिए एक ठीक की वजह से वैसे भी ViewHandler के लिए आवरण बनाने के लिए किया था,)। साथ ही, 'बाहरी कॉन्टेक्स्ट # रीडायरेक्ट()' बहुत काम करता है। एक बार फिर, एक अच्छा जवाब :) – bluefoot