ExpenseClaim -> Employee -> Address (street, city, state, zipCode, country)If a property value is not null, it will be added in query criteria. So entity property type must not be a primitive type since it will always have a default value (e.g. false for boolean, 0 for integer). So use its wrapper type instead. For example,
public class Employee {
private Boolean partTime;
@Column(nullable=false)
public Boolean getPartTime() {
return this.partTime;
}
public void setPartTime(Boolean partTime) {
this.partTime = partTime;
}
}
public PageNavigation showExpenseClaimQuery(ContainerRenderRegions containerRenderRegions) {
EntityViewConfig viewConfig = new EntityViewConfig(ViewType.QUERY);
ExpenseClaim expenseClaim = new ExpenseClaim();
EntityDataSource entityDataSource = new EntityDataSource(expenseClaim);
entityDataSource.setRenderRegions(containerRenderRegions);
ContainerBean containerBean = containerRenderRegions.getTargetContainerBean();
return containerBean.showEntity(ExpenseClaim.class, entityDataSource, viewConfig, false);
}
view={ViewType.ALL}
view={ViewType.QUERY}
view={ViewType.ENTITY, ViewType.QUERY}
@Query annotation specifies EntityProperty type (if different from ViewType.ENTITY),
render style(if different from ViewType.ENTITY), whether a property can be group-by,
order-by and/or keyword matching property, match type, etc. For example,
@Property(name="summary", view={ViewType.ALL},
renderStyle=@RenderStyleDef(size=30),
query=@Query(keyword=true)),
@Property(name="description", view={ViewType.ENTITY, ViewType.QUERY},
renderStyle=@RenderStyleDef(style=RenderStyle.INPUT_HTML),
query=@Query(keyword=true)),
@Property(name="employee", view={ViewType.ALL},
query=@Query(groupByProperty=true, orderByProperty=true)),
@Property(name="createdDate", view={ViewType.ALL},
mode={ModeType.VIEW, ModeType.EDIT, ModeType.QUERY}, editable=EditControl.QUERY_ONLY,
query=@Query(entityPropertyType=RangeEntityProperty.class, orderByProperty=true,
renderStyle=@RenderStyleDef(size=8)))
EntityViewConfig queryViewConfig = new EntityViewConfig(ViewType.QUERY);
queryViewConfig.setPropertiesToShow("name", "type");
//queryViewConfig.setPropertiesToHide("name", "type");
public class ExpenseClaimBean extends EntityBackingBean<ExpenseClaim> {
@Override
public StatisticsProperty[] getStatisticsProperties() {
return new StatisticsProperty[]{
new StatisticsProperty(ExpenseClaim.PROPERTY_TOTAL_EXPENSE, Aggregate.SUM)};
}
}
Multiple group-by properties can be selected by user from search options.
To override default orders, for example, order by employee type ascending and hiredDate descending:
public class EmployeeBean extends EntityBackingBean<Employee> {
@Override
public List<CriteriaOrder> getDefaultQueryOrders() {
List<CriteriaOrder> orders = new ArrayList<CriteriaOrder>(2);
orders.add(DetachedCriteria.asc("type"));
orders.add(DetachedCriteria.desc("hiredDate"));
return orders;
}
}
To add entity default query orders to a QueryCriteria for building a CriteriaQuery,
CriteriaQueryBuilder builder = ;
// add default orders
EntityDefaultOrdersBuilder<Employee, Employee> defaultOrdersBuilder =
new EntityDefaultOrdersBuilder<Employee, Employee>(Employee, null, containerBean);
QueryCriteria<Employee, Employee> queryCriteria = new QueryCriteria<Employee, Employee>(
Employee.class, Employee.class, builder, defaultOrdersBuilder);
public class ExpenseClaimItemBean extends EntityBackingBean<ExpenseClaimItem> {
@Override
public EntityJoinGraph<ExpenseClaimItem> getQueryJoinGraph() {
return new EntityJoinGraph<ExpenseClaimItem>(ExpenseClaimItem.class,
new Object[]{"expenseClaim.employee.address", JoinType.LEFT}
);
}
}
All entity joins are inner joins except that expenseClaim.employee left outer joins address.
To change the default query criterion for a property, for example, a custom property, override the getQueryCriterion(...) method of EntityBackingBean.
@Override
public <Q> PropertyQueryCriterion getQueryCriterion(CriteriaBuilder criteriaBuilder,
CriteriaQuery<Q> criteriaQuery,
EntityProperty<T> queryProperty) throws SystemException {
if (queryProperty.getName().equals("customProperty")) {
Predicate criterion = ;
return new PropertyQueryCriterion(criterion, false);
}
return super.getQueryCriterion(criteriaBuilder, criteriaQuery, queryProperty);
}
@Property(name="homeAddress", view={ViewType.ENTITY, ViewType.QUERY},
query=@Query(entityPropertyType=CheckNotNullProperty.class,
renderStyle=@RenderStyleDef(style=RenderStyle.SELECT_ONE_MENU)))
public class HrMenuNodeFactory extends ModuleMenuNodeFactory {
@Override
protected void createSubMenu() throws SystemException {
TypeDescriptor[] types = new TypeDescriptor[] {
new TypeDescriptor<Employee>(Employee.class,
null, viewConfig, null, true, null, null)};
addTypedMenuNodes(this, rootMenuNode, types);
}
}
If query is enabled, a query bean can be opened from the submenu of the menu node. The render regions of a query bean can be specified by the queryRenderRegions of a TypeDescriptor. ContainerBean.getDefaultQueryRenderRegions() provides the default render regions to show the query bean in the containerBean. Query bean can also be opened from query results bean to refine search results if the query bean can be obtained from its EntityDataSource by EntityDataSource.getQueryFormBean().
ContainerBean.getDefaultQueryResultRenderRegions()
To show query results in different regions or containerBean, change the render regions of
the Search command partial behavior. For example,
public class MyBackingBean extends EntityBackingBean<MyType> {
@Override
public void refreshMenuBeans() throws BackingBeanException, SystemException {
super.refreshMenuBeans();
if (!viewConfig.isQueryView())
return;
String queryCommand = getQueryCommand();
MenuNode searchMenuNode = getMenuNode(queryCommand, false, true);
PartialBehaviorSupport partialBehaviorSupport = searchMenuNode.getPartialBehaviorSupport();
PartialBehavior partialBehavior = partialBehaviorSupport.getPartialBehavior(PartialBehavior.EVENT_ACTION, false);
ContainerRenderRegions queryResultsRenderRegions = ;
partialBehavior.setContainerRenderRegions(queryResultsRenderRegions);
}
}
EntityViewConfig queryViewConfig = new EntityViewConfig(ViewType.QUERY); queryViewConfig.setQuickQueryProperties("id", "name", "type");Those properties not in the Quick tab will be grouped under the Advanced tab.
Alternatively, override the getDefaultPrimaryProperties() method of EntityBackingBean.
@Override
protected List<String> getDefaultPrimaryProperties(ViewType viewType) {
return Arrays.asList("id", "name", "type");
}
Entity primary properties are also used in entity selections dialog for an EntityProperty.