Entity Batch Print

Display a list of entities using one of its FormDesign(s) print-friendly with form separator and page break. The number of forms in a page and the margin between forms can be adjusted. An entity may need more than one form if it has entity list form bean with multiple pages.

For example, in ExampleHR 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, For example, ExpenseClaimPrintBean:

	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();
		  	
			Date date = new Date();
			Date yearStartDate = DateUtil.getStartTimeOfYear(date);
		  	DatePeriod datePeriod = ReportUtil.getDatePeriod(period, 
		  			yearStartDate, true);
		  	criteriaElements.add(ReportUtil.getDateCriterion(
		  			ExpenseClaim.PROPERTY_CREATED_DATE, datePeriod));
		  	 	
			// 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 fetchGraph = new EntityFetchGraph(ExpenseClaim.class, false);
		  	fetchGraph.addProperty(ExpenseClaim.PROPERTY_EXPENSE_CLAIM_ITEMS, JoinType.LEFT);
		    criteria.setEntityFetchGraph(fetchGraph);
		  	
		  	return criteria;
		}
	  
	}

Open Batch Print Form

Show a batch print form in QUERY view. For example,
	
	EntityViewConfig viewConfig = new EntityViewConfig(ViewType.QUERY);

	ExpenseClaimPrint expenseClaimPrint = new ExpenseClaimPrint();
	EntityDataSource<ExpenseClaimPrint> eds = new EntityDataSource<ExpenseClaimPrint>(expenseClaimPrint);
	eds.setRenderRegions(containerRenderRegions);
	containerRenderRegions.getTargetContainerBean().showEntity(ExpenseClaimPrint.class, eds, viewConfig, false);
The PrintView command will be added, which will open a new browser tab 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.