For example, in Example HR module, retrieve a list of ExpenseClaim(s) and display them print-friendly. Define batch print query form:
public class ExpenseClaimPrint extends EntityBatchPrintBase<ExpenseClaim> {
// date period
private String period;
private Employee employee;
@Column(nullable=false)
public String getPeriod() {
return period;
}
public void setPeriod(String period) {
this.period = period;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
In its batch print EntityBackingBean,
public class ExpenseClaimPrintBean extends EntityBatchPrintBean<ExpenseClaimPrint, ExpenseClaim> {
@UIDefines({
@UIDefine(name=UI_QUERY_PROPERTIES, value={
@Property(name="period", view={ViewType.QUERY},
help=@HelpDef(message="PeriodInputHelp", view={ViewType.QUERY}, popup=true, force=false)),
@Property(name="employee", view={ViewType.QUERY})
})
})
public boolean hasPropertyAnnotations() {
return true;
}
@Override
protected Integer getPrintEntityCountLimit() {
return 100;
}
@Override
protected Class<ExpenseClaim> getPrintEntityType() {
return ExpenseClaim.class;
}
@Override
protected QueryCriteria<ExpenseClaim, ExpenseClaim> buildQueryCriteria() throws SystemException {
// query: ExpenseClaim
List<CriteriaElement> criteriaElements = new ArrayList<CriteriaElement>();
ExpenseClaimPrint expenseClaimPrint = this.getEntity();
// date period
String period = expenseClaimPrint.getPeriod();
LocalDate yearStartDate = getYearStartDate();
DataAccessUnit dataAccessUnit = getDataAccessUnit();
ReportUtil reportUtil = new ReportUtil(dataAccessUnit);
DatePeriod datePeriod = reportUtil.getDatePeriod(yearStartDate, period, null, true);
criteriaElements.add(PropertyCriteriaQueryBuilder.getDateCriterion(
ExpenseClaim.PROPERTY_CREATED_DATE, datePeriod, false, getTimeZone()));
// employee
Employee employee = expenseClaimPrint.getEmployee();
if (employee != null)
criteriaElements.add(CriteriaElement.eq(ExpenseClaim.PROPERTY_EMPLOYEE, employee));
// order by
criteriaElements.add(CriteriaElement.asc(ExpenseClaim.PROPERTY_NID));
QueryCriteria<ExpenseClaim, ExpenseClaim> criteria = new QueryCriteria<ExpenseClaim, ExpenseClaim>(
ExpenseClaim.class, criteriaElements,
ExpenseClaim.class, ExpenseClaim.class);
// fetch lazy
EntityFetchGraph<ExpenseClaim> fetchGraph = new EntityFetchGraph<ExpenseClaim>(ExpenseClaim.class, false);
fetchGraph.addProperty(ExpenseClaim.PROPERTY_EXPENSE_CLAIM_ITEMS, JoinType.LEFT);
criteria.setEntityFetchGraph(fetchGraph);
return criteria;
}
}
EntityViewConfig viewConfig = new EntityViewConfig(ViewType.QUERY);
ExpenseClaimPrint expenseClaimPrint = new ExpenseClaimPrint();
EntityDataSource<ExpenseClaimPrint> eds = new EntityDataSource<ExpenseClaimPrint>(expenseClaimPrint);
containerBean.showEntity(ExpenseClaimPrint.class, eds, viewConfig, false);
The PrintView command will be added, which will open a new window to
display print-friendly paged entities. Note that the margins above the first
form and below the last form on a page is zero, since page top and bottom margins
in print setup will serve the purpose.
For complete example source code, refer to Example HR module.