Data validate before print

HI,

When I click the print button printing starts immediately, but I need some validations are performed before, ie, printing should only start if the validations return true.

How can I implement this feature?

This is my code now.
Button print= new Button(“Print”);
OnDemandStreamResource myResource = report.createResource(parameters);
OnDemandFileDownloader fileDownloader = new OnDemandFileDownloader(myResource);
fileDownloader.extend(print);

Hi,

Anybody can help me, how can i perform validation before the print ?