Thursday, 22 September 2016

TO ADD CUSTOM VALIDATORS IN ADF



TO ADD CUSTOM VALIDATORS IN ADF

The Code is tested on ADF 11.1.2.4.0 version.
Sometimes Business rule cannot be applied on Entity object to throw out error as per customer requirements.
We need to add custom validations to throw error during run time for an application.
Below code represents a scenario where I want to throw an error at run time if the Item quantity is in decimal point for particular Item UOM(Unit of measure) .

public void ValidatorReqQty(FacesContext facesContext,
                            UIComponent uIComponent, Object object) throws ValidatorException
{
DCBindingContainer bindings4 = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings = bindings4.findIteratorBinding("XXPRIVI_MATERIAL_REQUESTView1Iterator");
ViewObject XXPRIVI_MATERIAL_REQUESTView1 = dcItteratorBindings.getViewObject();
Row dv = XXPRIVI_MATERIAL_REQUESTView1.getCurrentRow();
       
            FacesContext fc = FacesContext.getCurrentInstance();
            BigDecimal ReqQuantityCurr  = (BigDecimal)object;
            System.out.println("ReqQuantityCurr" + ReqQuantityCurr);
           
String ReqQuantityCurrStr = (String)ReqQuantityCurr.toString();
System.out.println("ReqQuantityCurrStr" + ReqQuantityCurrStr);
           
String ReqQuantityCurrStrWithDec = (String)ReqQuantityCurr.setScale(2,BigDecimal.ROUND_UP).toString();
System.out.println("ReqQuantityCurrStrWithDec" + ReqQuantityCurrStrWithDec);
           
String DecnumberCurr = ReqQuantityCurrStrWithDec.substring(ReqQuantityCurrStrWithDec.indexOf(".")).substring(1);
System.out.println("DecnumberCurr" + DecnumberCurr  );
           
String CompareUom = "EA" ;
           
if(Uom.equals(CompareUom) && DecnumberCurr.compareTo("00") != 0)
     {
           throw new ValidatorException(new FacesMessage("Quantity cannot be in decimal for UOM 'EA'."));
      }
}

Now Run the project.

The below image represents the validation error as per the requirement.
Love ADF... :)




 

Wednesday, 17 August 2016

CODE TO CALL "OUT" PARAMETERS FROM PLSQL PROCEDURES AND GET THEM IN BACKING BEAN IN ADF



CODE TO CALL 'OUT' PARAMETERS FROM  PLSQL PROCEDURES AND GET THEM IN BACKING BEAN IN ADF:

The Code is tested on ADF 11.1.2.4.0 version.

Sometimes we have one or more return results as per our requirement.To fulfil this requirement we make use of procedures with "OUT" parameters , as function gives us only one return result.

Here the below code explains us the process of implementing pl-sql procedures in ADF.

1) Code to call procedure in adf:


Step 1: Create a procedure 'GET_INVRESPONSEKEY_USERNM'  in package named 'adf_pkg'  in  database which gives two out parameters and has one in parameter.
 
Step 2:  Add the code in App Module which calls the procedure.


 
public String[] GET_INVRESPONSEKEY_USERNM(int USERID)
{

       

       CallableStatement st1 = null;

      

               try {


st1 =    getDBTransaction().createCallableStatement("begin adf_pkg.GET_INVRESPONSEKEY_USERNM(?,?,?); end;",0);

     

          st1.setInt(1,USERID);

          st1.registerOutParameter(2,Types.VARCHAR);

          st1.registerOutParameter(3,Types.VARCHAR);

          st1.executeUpdate();

                     

           String      RESPONSIBILITY_KEY = st1.getString(2);

           String        USER_NAME = st1.getString(3);

                     

System.out.println("RESPONSIBILITY_KEY=" + RESPONSIBILITY_KEY);

System.out.println("USER_NAME=" + USER_NAME);

                     

return new String[] {RESPONSIBILITY_KEY,USER_NAME} ;

                     

                        
catch (SQLException e) 
  {       

                  throw new JboException(e);    

      }
}



Step 3 : Drag and drop the function name by editing Client Interface.
 

Step  4 : To get the 'Out' parameters in backing bean of jsf page add the below code. 

BindingContainer bindings = getBindings();

OperationBinding operationBinding =bindings.getOperationBinding("GET_INVRESPONSEKEY_USERNM");

Object result = operationBinding.execute();

Object ReturnValue[] = (Object[])operationBinding.getResult();

         
String RESPONSIBILITY_KEY = (String)ReturnValue[0];

System.out.println("RESPONSIBILITY_KEY=" + RESPONSIBILITY_KEY);

      
String USER_NAME  = (String)ReturnValue[1];

System.out.println("USER_NAME=" + USER_NAME);