I have to perform two operations on button click.
-
call a method in a bean which will return a url and it will be set in some variable.
-
after that I have to open that url in another tab. I am using the action attribute of CommandButton and it is setting the URL value correctly, but how do I open that url as pdf in a new tab. i.e “URL of pdf should open in a new tab”
Code sample as follows:
<div class="form-options">
<h:commandButton value="Download Report" styleClass="btn btn-primary btn-icon buttonCustom" actionListener="#{reportBean.GenerateReport}">
</h:commandButton>
</div>
Hope I unterstood you right. This worked for me:
target="_blankin the parent<h:form>(taken from this questions answer)XHTML-Code:
As this approach applies the
target="_blank"to all non-ajax calls, here’s another way using Javascript:Java-Code:
If you have to forward to an external link, see this question