is there a build-in mechanism to conditionally redirect to another view? I want the user to be redirected from the login page to the "home page" if he/she is already logged in.
I already have two basic approaches, but for the first I have no idea how to achieve and the second is sort of a dirty workaround.
<meta http-equiv="Refresh" content="0; URL=home.jsf" />
and let it be rendered conditionally (EL : #{login.loggedIn}
)<h:panelGroup />
which will also be conditionally rendered, containing some JavaScript doing the redirect.Is there a way to achieve 1 or even another, more elegant solution? :-)
Thanks
You could use <f:event type="preRenderView">
for this.
E.g.
<f:event type="preRenderView" listener="#{login.checkAlreadyLoggedin}" />
with
public void checkAlreadyLoggedin() throws IOException {
if (isLoggedIn()) {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/home.xhtml");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With