I have a JSF page containing a Pie Chart. The idea is that when the Sector of Pie Chart is clicked the application redirects to another page. I am facing Challenges Redirecting Because it is Only taking Full url to the page which is not Dynamic as it will change depending on the environment. My ItemSelect Method is :
public void itemSelect(ItemSelectEvent event) {
try {
FacesContext.getCurrentInstance().
getExternalContext().redirect("http://localhost:8084/SIMBANK_BI/faces/OpenedAccountsProductTypeLevel.xhtml");
} catch (IOException asd) {
System.err.println(asd.getMessage());
}
}
My JSF Page:
<left>
<p:growl id="growl" showDetail="true" />
<p:pieChart id="custom" value="#{OpenedAccountsBranchLevelBean.pieModel}" legendPosition="w" showDataLabels="true"
style="width:500px;height:400px" sliceMargin="2">
<p:ajax event="itemSelect" listener="#{OpenedAccountsBranchLevelBean.itemSelect}" update="growl" />
</p:pieChart>
</left>
I have tried;
FacesContext.getCurrentInstance().
getExternalContext().redirect("/faces/OpenedAccountsProductTypeLevel.xhtml");
I have also tried:
FacesContext.getCurrentInstance().
getExternalContext().redirect("/OpenedAccountsProductTypeLevel.xhtml");
My Question is how Can I redirect without Having to place in the Entire URL??
Try using
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest origRequest = (HttpServletRequest)context.getExternalContext().getRequest();
contextPath = origRequest.getContextPath();
try {
FacesContext.getCurrentInstance().getExternalContext()
.redirect(contextPath + "/faces/OpenedAccountsProductTypeLevel.xhtml");
} catch (IOException e) {
e.printStackTrace();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.