Pages - Menu

Sunday, September 15, 2013

Handle Unique Values Programmatically || Oracle ADF

Hi
Few Days ago, i faced new situation to handle some of Unique Constrains but in this time, we have to use Programmatically way ..
Many of people will ask, why ? as we can do it in the Custom Message bundle for Model Layer using Constrain Name or Jbo Error Code ..
My answer, as in last releases of 11.1.2.*, we face a problem between LOV for PK/FK Attributes , and normal way to handle Unique Message is not working in this time !!
so, in our new Situation, and the only working way, is to reset from Managed/Back Bean to UI Component describing the LOV item.
My Example, uses 1st Method to Check and 2nd to handle the exception.
  • in AM, we have to make a Method to check before commit.
    public Boolean CheckUniqueUserRoles(String UserId, String RoleId) {

        Boolean result = false;
        ViewObject userrole = getDBTransaction().findViewObject(“UserRolesLookup1”);
        Row[] _result = userrole.findByKey(new Key(new Object[] { UserId, RoleId }), 1);

        if (_result.length > 0) {
            result = true;
        } else {
            result = false;
        }
        userrole.setWhereClause(null);
        userrole.reset();
        return result;
    }
  • in Managed Bean in Back Bean Scope, you can use the following Method to Handle using above method ..
    public void HandleUserRolesUQ(ValueChangeEvent vce) {

        OperationBinding CheckUQ = (OperationBinding)cwc.AccessOperation(“CheckUniqueUserRoles”);
        CheckUQ.getParamsMap().put(“UserId”,
                                   cwc.AccessIteratorBinding(“UserRoles2Iterator”).getCurrentRow().getAttribute(“UserId”));
        CheckUQ.getParamsMap().put(“RoleId”, getRoleId().getValue());
        Object MyResult = CheckUQ.execute();

        if (((Boolean)MyResult).compareTo(true) == 0) {
            getRoleId().resetValue();
            cwc.Validate(cwc.getFacesContext(),
                         cwc.AccessBundleItemValue(“CS.view.CS-InterfaceBundle”, “ValidatorMessageHeader4”),
                         cwc.AccessBundleItemValue(“CS.view.CS-InterfaceBundle”, “ValidatorMessageFooter4”), 2);
        }

    }
Notes ..
- First Method should be included as a client Interface for AM in Model Layer.
  • Reference of cwc.AccessOperation
    public OperationBinding AccessOperation(String OperationName) { // Access OperationBinding
        return (OperationBinding)getBindings().getOperationBinding(OperationName);
    }
  • Reference of cwc.AccessIteratorBinding
    public DCIteratorBinding AccessIteratorBinding(String IteratorName) { // Access IteratorBinding
        return (DCIteratorBinding)getBindings().get(IteratorName);
    }
  • Reference of cwc.Validate
    public void Validate(FacesContext MyContext, String Header, String Footer,
                             int Level) { // Force Validation
        FacesMessage MyMessage = new FacesMessage();
        if (Level == 1) {
            MyMessage = new FacesMessage(MyMessage.SEVERITY_FATAL, Header, Footer);
        } else if (Level == 2) {
            MyMessage = new FacesMessage(MyMessage.SEVERITY_ERROR, Header, Footer);
        } else if (Level == 3) {
            MyMessage = new FacesMessage(MyMessage.SEVERITY_WARN, Header, Footer);
        } else if (Level == 4) {
            MyMessage = new FacesMessage(MyMessage.SEVERITY_INFO, Header, Footer);
        }

        MyContext.addMessage(null, MyMessage);

    }
  • Reference of cwc.AccessBundleItemValue
    public String AccessBundleItemValue (String BundleName , String BundleNameItem){
        ResourceBundle bundle =   BundleFactory.getBundle(BundleName);
        return bundle.getString(BundleNameItem);
    }

No comments:

Post a Comment