How to open pdf file in new window in JSF

<code>
<h:commandLink styleClass=”link-stock”
ajax=”false” immediate=”false” target=”_blank” >
<h:outputText value=”#{msg[‘pds.godownwisestock’]}” />

<p:fileDownload  contentDisposition=”inline” value=”#{applicationBean.downloadStockAsPDF}” />
</h:commandLink></code>

JSF Send asynchronous request using ajax

1) Create hidden ajax buttons and set “async=true” for those buttons to call parallel.
ex:

<p:commandButton id="districtUpdateCommodity" value="Test" immediate="true" async="true"
											actionListener="#{dashBoardBean.updateDistrictLevelDashboardCommodityDashBoardDto}"
											update="myPanel" style="display:none" />
<p:commandButton id="districtUpdateSales" value="Test" immediate="true" async="true"
											actionListener="#{dashBoardBean.updateDistrictLevelDashboardCommodityDashBoardDto}"
											update="myPanel" style="display:none" />

2) This buttons won’t call directly. We need to call by jquery on load method.

document.getElementById('form:reportQueryForm:districtUpdateSales').click(); document.getElementById('form:reportQueryForm:districtUpdateCommodity').click();

How to redirect session time out automatically in jsf – primefaces

option1:


&lt;meta http-equiv="refresh"    content="#{facesContext.externalContext.sessionMaxInactiveInterval};url=#{request.contextPath}/session-timeout.xhtml" /&gt;

option2: The magic we can do with the help of PrimeFaces idle monitor.

&lt;p:idleMonitor timeout="600000"&gt;
&lt;p:ajax event="idle" listener="#{loginBean.onIdle}" update="@this form" /&gt;
&lt;!-- &lt;p:ajax event="active" listener="#{loginBean.onActive}" update="@this form" /&gt; --&gt;
&lt;/p:idleMonitor&gt;

Added below code in your managed bean
public void onIdle() {
/* FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
"No activity.", "What are you doing over there?"));*/
extCon = FacesContext.getCurrentInstance().getExternalContext();
extCon.invalidateSession();
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("session-timeout.xhtml?faces-redirect=true");
} catch (IOException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
}

public void onActive() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
“Welcome Back”, “Well, that’s a long coffee break!”));
}