更新时间:2023-12-03 10:25:40
您可以用一种更加优雅的方式来实现它,而无需在页面中声明outputPanel:
You can do it in a more elegant way, without the need of the outputPanel declared in the page:
JavaScript函数:
Javascript function:
function print(component){
var out = document.createElement('div');
out.appendChild(PF(component).exportAsImage());
var innerHTML = out.innerHTML;
var openWindow = window.open('', 'Report', '');
openWindow.document.write(innerHTML);
openWindow.document.close();
openWindow.focus();
openWindow.print();
openWindow.close();
}
为图表定义widgetVar:
Define widgetVar for chart:
<p:chart widgetVar="chart2" type="bar" model="#{chartsBean.barModel2}" />
调用打印功能:
Call the print function:
<p:commandLink id="lnk" onclick="print('chart2')"/>