I tried another approach, extend AdminProductController and override viewEntityList to add merchant filter as follows:
Code: Select all
@Override
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars);
Long merchantId = BusinessUserState.getMerchantId();
if (merchantId != null) {
FilterAndSortCriteria merchantFilter = new FilterAndSortCriteria("merchant.id", String.valueOf(merchantId));
ppr.addFilterAndSortCriteria(merchantFilter);
}
...
...
...
}
This works perfectly to filter the products by merchant. However, this works only when merchant property of MerchantProduct not be excluded from @AdminPresentation:
Code: Select all
@ManyToOne(targetEntity = BusinessAccountImpl.class)
@JoinColumn(name = "BUSINESS_ACCOUNT_ID")
@AdminPresentation(friendlyName = "MerchanktProduct_Merchant", visibility = VisibilityEnum.HIDDEN_ALL)
protected BusinessAccount merchant = new BusinessAccountImpl();
This will show all BusinessAccount properties on product's grid view and entity view. It seems @AdminPresentation's visibility = VisibilityEnum.HIDDEN_ALL not working properly. If excluding BusinessAccount from product, the merchant filter won't work because the entities returned from DynamicResultSet does not include merchant property and of course the merchant filter doesn't work.
Is this a bug?