I have to generate reports based on various parameters which would be provided dynamically. In certain contexts, the parameters may be null. For example, from the table Person with id, name, age, sex and maritalStatus as fields, I would have to generate reports on married male persons of age 30. Some other times, it may be required to get married female without considering age. If I use the same jasper for both these cases, the age constraint will be null in second case. Is there any way to manage this condition?
Also, is it possible to dynamically specify which all fields should be produced in the report?
You should try Dynamic jasper. This is exactly the type of use case the dynamic jasper is designed for. You can use same template to generate reports with different columns.
For more info : http://dynamicjasper.com/
The sample of using the JasperReport API for generating report dynamically:
You can find more samples in %JasperReportsFolder%/demo/samples folder from the JasperReports distribution package.