Sunday, June 12, 2011

valuechangelistner phase control

        if(valueChangeEvent.getNewValue() != null) {

            if (valueChangeEvent.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
                //@CodeCleanup System.out.println("inside defaultCountryTaxDefaultControls 2");
                valueChangeEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
                valueChangeEvent.getComponent().queueEvent(valueChangeEvent);
            }
            else {
                //@CodeCleanup System.out.println("inside defaultCountryTaxDefaultControls again");
                //TaxUIHelper.setPageFlowScopeVariable("GroupCode",newVal);
                invokeEL("#{bindings.defaultCountryTaxDefaultControls.execute}");
            }

        }

Tuesday, May 24, 2011

Preparing value submitted bind variable query in ExecuteQuery

    public void executeQuery() {
        System.out.println("getQuery before executeQuery:" + getQuery());
        performCustomViewCriteriaValidation();
        super.executeQuery();
        List vcTempVals = new ArrayList();
        System.out.println("getQuery after executeQuery:" + getQuery());
        String formattedQuery = getQuery();

        ViewCriteria[] vcs =
            getApplyViewCriterias(ViewCriteria.CRITERIA_MODE_QUERY);

        if (vcs != null & vcs.length > 0) {
            for (ViewCriteria v : vcs) {
                for (ViewCriteriaRow vcr :
                     (List<ViewCriteriaRow>)v.getRows()) {
                    //                    ViewCriteriaRow vcr = (ViewCriteriaRow)v.first();
                    if (vcr != null) {
                        ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
                        if (vcis != null && vcis.length > 0) {
                            for (int j = 0; j < vcis.length; j++) {
                                ViewCriteriaItem vci = vcis[j];
                                if (vci != null &&
                                    vci instanceof ViewCriteriaItemCompound) {
                                    ViewCriteriaItemCompound vcic =
                                        (ViewCriteriaItemCompound)vci;
                                    for (int k = 0; k < vcic.getItemCount();
                                         k++) {
                                        vci =
(ViewCriteriaItem)vcic.getItem(k);
                                        if (vci != null) {
                                            Object o = vci.getValue();
                                            Object on = vci.getColumnName();
                                            if (!vci.getOperator().equals(JboCompOper.OPER_IS_BLANK) &&
                                                !vci.getOperator().equals(JboCompOper.OPER_IS_NOT_BLANK) &&
                                                vci.getValue() != null) {
                                                System.out.println("vc attribute from compound:" +
                                                                   o);
                                                System.out.println("vc attribute name from compound:" +
                                                                   on);
                                                vcTempVals.add(vci.getValue());
                                            }
                                        }
                                    }
                                } else if (vci != null) {
                                    Object o = vci.getValue();
                                    Object on = vci.getColumnName();
                                    if (!vci.getOperator().equals(JboCompOper.OPER_IS_BLANK) &&
                                        !vci.getOperator().equals(JboCompOper.OPER_IS_NOT_BLANK) &&
                                        vci.getValue() != null) {
                                        System.out.println("vc attribute:" +
                                                           o);
                                        System.out.println("vc attribute name:" +
                                                           on);
                                        vcTempVals.add(vci.getValue());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        Pattern p = Pattern.compile(":vc_temp\\w*");
        String[] arr = p.split(formattedQuery);
        formattedQuery = "";
        for (int i = 0; i < arr.length; i++) {
            //                              System.out.println("mukka:" + arr[i]);
            if (i == arr.length - 1) {
                formattedQuery = formattedQuery + arr[i];
            } else {
                formattedQuery =
                        formattedQuery + arr[i] + "'" + vcTempVals.get(i) +
                        "'";
            }
        }

        ADFContext.getCurrent().getExpressionEvaluator().setValue("#{pageFlowScope.AllocExtractsQuery}",
                                                                  formattedQuery);
        System.out.println("end of executeQuery:" + formattedQuery);

    }

    private void performCustomViewCriteriaValidation() {
        ViewCriteria[] vcs =
            getApplyViewCriterias(ViewCriteria.CRITERIA_MODE_QUERY);
        Boolean isValidRequiredVc = true, isValidSelcRequiredVc=true;
        HashMap selcRequiredVcItems = new HashMap();

        if (vcs != null & vcs.length > 0) {
            for (ViewCriteria v : vcs) {
                ViewCriteriaRow vcr = (ViewCriteriaRow)v.first();
                if (vcr != null) {
                    ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
                    if (vcis != null && vcis.length > 0) {
                        for (int j = 0; j < vcis.length; j++) {
                            ViewCriteriaItem vci = vcis[j];
                            if (vci != null &&
                                vci instanceof ViewCriteriaItemCompound) {
                                ViewCriteriaItemCompound vcic =
                                    (ViewCriteriaItemCompound)vci;
                                for (int k = 0; k < vcic.getItemCount(); k++) {
                                    vci = (ViewCriteriaItem)vcic.getItem(k);
                                    if (vci != null) {
                                        Object o = vci.getValue();
                                        Object on = vci.getColumnName();
                                        if (vci.VCITEM_REQUIRED ==
                                            vci.getRequired() &&
                                            vci.getValue() == null) {
                                            System.out.println("Null value for vc required attribute name from compound:" +
                                                               on);
                                            isValidRequiredVc = false;
                                            break;
                                        } else if (vci.VCITEM_SELECTIVELY_REQUIRED ==
                                                   vci.getRequired()) {
                                            System.out.println("vc selctively required attribute name from compound:" +
                                                               on);
                                            selcRequiredVcItems.put(on,o);
                                        }
                                    }
                                }
                            } else if (vci != null) {
                                Object o = vci.getValue();
                                Object on = vci.getColumnName();
                                if (vci.VCITEM_REQUIRED == vci.getRequired() &&
                                    vci.getValue() == null) {
                                    System.out.println("Null value for vc required attribute name:" +
                                                       on);
                                    isValidRequiredVc = false;
                                    break;
                                } else if (vci.VCITEM_SELECTIVELY_REQUIRED ==
                                           vci.getRequired()) {
                                    System.out.println("vc selctively required attribute name:" +
                                                       on);
                                    selcRequiredVcItems.put(on,o);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!isValidRequiredVc) {
            throw new JboException("Please enter all required attributes for search!");
        }
        else if(selcRequiredVcItems.size() != 0) {
            isValidSelcRequiredVc = false;
            for(Object obj:selcRequiredVcItems.keySet()) {
                if(selcRequiredVcItems.get(obj) != null) {
                    isValidSelcRequiredVc = true;
                    break;
                }
            }
            if (!isValidSelcRequiredVc) {
                throw new JboException("Please enter any of the selectively required attribute for search!");
            }
        }
    }
 

Generate custom where clause fragment for the ViewCriteriaItem

@Override
public String getCriteriaItemClause(ViewCriteriaItem vci) {
 if (vci.getAttributeDef().getName().equals("DepartmentName") &&
    vci.getViewCriteria().getName().contains("DeptSampleVC")) {
    if (vci.getViewCriteria().getRootViewCriteria().isCriteriaForQuery()) {
    return getINClauseForDatabaseUse(vci);
    } else {
    return getINClauseForCache(vci);
    }
 } else {
    return super.getCriteriaItemClause(vci);
 }

}
protected String getINClauseForDatabaseUse(ViewCriteriaItem vci) {

 String bindVarValue = getCommaDelimitedDeptNames();
 String bindVarName = "CommaDelimitedDeptNames";
 String whereCluase = "1=1";
 if (bindVarValue != null && bindVarValue.trim().length() != 0) {
    whereCluase =
        this.getEntityDef(0).getAliasName() + ".DEPARTMENT_NAME IN (select /*+ CARDINALITY(A, 50) */ * from TABLE (cast (in_list_char ( :" +
        bindVarName + " ) as ChartableType))A)";
 }
 return whereCluase;
}

protected String getINClauseForCache(ViewCriteriaItem vci) {
 String whereCluase = "1=1"; 
 return whereCluase;
}

Tuesday, December 14, 2010

How to reset a UI component and all of its childs?

    private void resetUnbound(UIComponent component) {
       System.out.println("==resetUnbound()==");
     
       FacesContext context = FacesContext.getCurrentInstance();
       java.util.Stack<UIComponent> stack = new java.util.Stack<UIComponent>();
       stack.add(component);
       while (!stack.isEmpty())
       {
         UIComponent target = stack.pop();
         System.out.println("target.getClientId(context): " + target.getClientId(context));
         if (target instanceof UIXEditableValue) {
             ValueExpression ve = ((UIXEditableValue) target).getValueExpression("value");
             // if the component has a value binding, setting the value will override
             // the EL.
             if (ve == null) {
                 ((UIXEditableValue) target).setValue("");
             }
             ((UIXEditableValue) target).setSubmittedValue(null);
         }
         for (java.util.Iterator<UIComponent> ci = target.getFacetsAndChildren(); ci.hasNext();) {
              stack.push(ci.next());
         }
       }
    }