I have a requirement that before the page is going to load i want to check whether query string exists or not if query string exists then i want to redirect to another page instead of current page how can i handle this type of requirement in JSF 2.
Thanks in advance
When on JSF 2.2, you can use <f:viewAction>
for this.
<f:metadata>
<f:viewParam name="paramName" value="#{bean.paramName}" />
<f:viewAction action="#{bean.check}" />
</f:metadata>
(paramName
is the name of your 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), you can use <f:event type="preRenderView">
for 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");
}
}
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