Let’s say I have this action in a JSF Managed Bean:
public String doSomething() {
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("msg", "Something was done successfully");
return "view?faces-redirect=true";
}
My view has an anchor element with the id msg. I want the url to have this anchor (for accessibility matters), like:
view.jsf#msg
Or whatever is my FacesServlet filter pattern.
return "view#msg?faces-redirect=true"; obviously will not work because JSF (mojarra at least) will try to evaluate view#msg as a view.
So my question is how to make JSF redirect to a URL with #msg in the end.
Oh, that’s nasty. It’s definitely worth an enhancement request at the JSF/Mojarra boys.
Your best bet is to send the redirect manually with help of
ExternalContext#redirect().(assuming that
FacesServletis mapped on*.xhtml)Alternatively, you could conditionally render a piece of JS which does that instead.