@SuppressWarnings("unchecked")
@Bean(scope = DefaultScopes.SESSION, aliases = "empCrud")
public JsfCrudAdapter employeeCrud() throws Exception {
JsfCrudAdapter adapter = cruds().get("Employee");
adapter.getController().addCrudControllerListener(new CrudControllerAdapter(){
@Override
public void afterUpdate(CrudEvent event) {
//throw new RuntimeException("Don't commit crudController"); un comment this to test tran support
}
});
/*
* Filter out employees who do not have a manager. This will create a
* "where employee.manager is null" to the query.
*/
adapter.getPaginator().addCriterion(Comparison.eq("manager", null));
adapter.getPaginator().filter();
/* Setup tasks and contacts DetailControllers. */
JsfDetailController taskController = new JsfDetailController(Task.class);
adapter.getController().addChild("tasks",
taskController);
taskController.setForceUpdate(true);
//taskController.setDao(repos().get("Task"));
adapter.getController().addChild("contacts",
new JsfDetailController(ContactInfo.class));
adapter.getPaginator().addOrderBy(OrderBy.asc("lastName"));
adapter.getPaginator().filter();
/*
* Setup directReports detail crudController. Make sure framework calls
* add/remove methods.
*/
JsfDetailController directReports = new JsfDetailController(
Employee.class);
RelationshipManager relationshipManager = directReports
.getRelationshipManager();
relationshipManager.setChildCollectionProperty("directReports");
relationshipManager.setAddToParentMethodName("addDirectReport");
relationshipManager.setRemoveFromParentMethodName("removeDirectReport");
adapter.getController().addChild("directReports", directReports);
return adapter;
}