Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Lazy DataTable: loading, sorting and filtering

pinguet62 edited this page Oct 30, 2014 · 3 revisions

Example of data table who uses a lazy data model:

<p:dataTable value="#{managedBean.lazyDataModel}"
             lazy="true">
    <!-- ... -->
</p:dataTable>
import org.primefaces.model.LazyDataModel;

@ManagedBean
class ManagedBean {
	LazyDataModel<User> lazyDataModel;
	
	LazyDataModel<User> getLazyDataModel() {
		return lazyDataModel;
	}
}

Basic usage

The base implementation of QuerydslLazyDataModel need only the service and the target type of objects:

@ManagedBean
class UsersManagedBean {
	// attribute
	// getter
	
	@Autowired UserService userService;
	
	@PostConstruct
	void init() {
		lazyDataModel = new QuerydslLazyDataModel<User>(userService, QUser.user);
	}
}

Overload

The base implementation can be overload:

class UserLazyDataModel extends QuerydslLazyDataModel<User> {
	UserLazyDataModel(UserService service) {
		super(service);
	}
	
	// overrides
}

The target type can be determined dynamically from the type of templatised class QuerydslLazyDataModel<T>.

Only the service must be set at instanciation:

@ManagedBean
class UsersManagedBean {
	// attribute
	// getter
	
	@Autowired UserService userService;
	
	@PostConstruct
	void init() {
		lazyDataModel = new UserLazyDataModel(userService);
	}
}

Clone this wiki locally