jsf 2 - Redirect before loading the page in JSF2 -
this question has answer here:
i have requirement before page going load want check whether query string exists or not if query string exists want redirect page instead of current page how can handle type of requirement in jsf 2.
thanks in advance
when on jsf 2.2, can use <f:viewaction>
this.
<f:metadata> <f:viewparam name="paramname" value="#{bean.paramname}" /> <f:viewaction action="#{bean.check}" /> </f:metadata>
(paramname
name of query string parameter)
private string paramname; // +getter+setter public string check() { if (paramname == null) { return "error.xhtml"; } return null; }
when not on jsf 2.2 yet (jsf 2.0/2.1), can use <f:event type="prerenderview">
this.
<f:metadata> <f:viewparam name="paramname" value="#{bean.paramname}" /> <f:event type="prerenderview" listener="#{bean.check}" /> </f:metadata>
private string paramname; // +getter+setter public void check() throws ioexception { if (paramname == null) { facescontext.getcurrentinstance().getexternalcontext().redirect("error.xhtml"); } }
Comments
Post a Comment