In many cases we need to conditionally change the validation property of view criteria ( we can change required / Selectively Required / Optional property in Query panel ).There is a method called setRequiredString(String) in ViewCriteriaItem object for achieving this requirement. Argument of this method is “Optional ” or “Required” or “SelectivelyRequired”. I am calling changeValidation() from queryOperationListener of af:Query component.In UI you can refresh your query component by self reference of partial trigger. Below code is self explanatory .
<af:query id="qryId1" headerText="Search" disclosed="true" value="#{bindings.Search_region_Name.queryDescriptor}" model="#{bindings.Search_region_Name.queryModel}" queryListener="#{backingBeanScope.BeanName.processQuery}" queryOperationListener="#{backingBeanScope.BeanName.queryOperationListener}" partialTriggers="::qryId1"/>
Managed Bean Codepublic void queryOperationListener(QueryOperationEvent queryOperationEvent) { JSFUtils.resloveMethodExpression("#{bindings.Employees1.collectionModel.makeCurrent}", Object.class, new Class[] { QueryOperationEvent.class }, new Object[] { queryOperationEvent }); if (queryOperationEvent.getOperation().equals(QueryOperationEvent.Operation.CRITERION_UPDATE)) { changeValidation(); } }
private void changeValidation() { DCDataControl dataControl = BindingContext.getCurrent().findDataControl("xxxAppModuleDataControl"); ApplicationModule am = (ApplicationModule)dataControl.getDataProvider(); ViewObject vo = am.findViewObject("VO_Instance_Name"); ViewCriteria viewCriteria = vo.getViewCriteriaManager().getViewCriteria("View_Criteria_Name"); ArrayList criteriaItems = (ArrayList)((ViewCriteriaRow)viewCriteria.getRows().get(0)).getCriteriaItems(); Iterator iterator = criteriaItems.iterator(); while (iterator.hasNext()) { ViewCriteriaItem item = (ViewCriteriaItem)iterator.next(); if (item.getName().equalsIgnoreCase("View_Attribute_Name")) { ((ViewCriteriaItem)criteriaItems.get(2)).setRequiredString("SELECTIVELY_REQUIRED"); if ((null != item.getValue())) { ((ViewCriteriaItem)criteriaItems.get(0)).setRequiredString("Optional"); ((ViewCriteriaItem)criteriaItems.get(1)).setRequiredString("Optional"); } else { ((ViewCriteriaItem)criteriaItems.get(0)).setRequiredString("SelectivelyRequired"); ((ViewCriteriaItem)criteriaItems.get(1)).setRequiredString("Required"); } } } }
No comments:
Post a Comment