You are trying to create an illegal URL - the snippet ( # ) is always the last part of the URL.
return "view?faces-redirect=true#msg" will be the correct URL.
Unfortunately, this snippet is shared by default by the NavigationHandler , at least in JSF 2.2.
While two options of BalusC are working , I have a third option. Wrap the NavigationHandler and ViewHandler small patch:
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; } }
(I still had to create a wrapper for ViewHandler due to a fix for JAVASERVERFACES-3154)
Tobias liefke
source share