Using PF 10, JSF 2.3
I try to open a url in a new tab when the user clicks on "Download report"
xhtml page:
<script type="text/javascript">
//<![CDATA[
function start() {
PF('statusDialog').show();
}
function stop() {
PF('statusDialog').hide();
}
//]]>
</script>
<h:form>
<p:menubar>
<p:menuitem value="Home" action="#{umigonBean.logout}" icon="pi pi-home"/>
<p:menuitem value="Download report" action="#{umigonBean.getReport}" onclick="PrimeFaces.monitorDownload(start);" icon="pi pi-arrow-down" oncomplete="PrimeFaces.monitorDownload(stop);"/>
</p:menubar>
</h:form>
Backing bean (session scoped, if this matters):
public void getReport(){
// report being generated in the form of a Google Slide...
// when it is generated, a redirect is made to the url of this Google Slide:
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().redirect("http://docs.google.com/etc");
}
The solutions suggested by @BalusC for a commandButton are:
<h:form target="_blank">
(does not apply as my form contains different links, and only this one should open a new tab)onclick="this.form.target='_blank'"
In my code above this would be:
onclick="this.form.target='_blank';PrimeFaces.monitorDownload(start);"
however when I choose this option, the action is not called (the "waiting" window appears and remains for ever).