Header Ads

Sum of Two Numbers Through Value Change Listener In ADF

In this article we will perform simple mathematical calculation 1+1 = 2 in ADF through value change listener. So lets start step by step. 

Step 1 :

First you need to create Value Change Listener on Field where you want to perform an action.



Step 2 :

Your ValueChangeListener has been created with the name of perBatchConsVCLstnr. Then you need to do the code for bean under this method.

Code:

    public void perBatchConsVCLstnr(ValueChangeEvent valueChangeEvent) {

        valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());

        BindingContainer bindings = getBindings();

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

        operationBinding.execute();

        AdfFacesContext.getCurrentInstance().addPartialTarget(chemicalTable);

    }


Step 3:

Now come to the AppModuleImpl.java and write the code as per you requirement

Code:

    public void perBatchConsVCLstnrBind(){

        double perBatchConsumption = 0, totalConsumption = 0, perBatchQuantity = 0;

        ViewObject chemRecDetVO = this.getChemiRecipiDetailVO1();

        try {

            perBatchConsumption = Double.parseDouble(chemRecDetVO.getCurrentRow()

                                                                 .getAttribute("PerBatchConsumption")

                                                                 .toString());

        } catch (NumberFormatException nfe) {

            // TODO: Add catch code

            nfe.printStackTrace();

        }

        try {

            perBatchQuantity = Double.parseDouble(chemRecDetVO.getCurrentRow()

                                                                 .getAttribute("PerBatchQuantity")

                                                                 .toString());

        } catch (NumberFormatException nfe) {

            // TODO: Add catch code

            nfe.printStackTrace();

        }

        totalConsumption = perBatchConsumption * perBatchQuantity;

        chemRecDetVO.getCurrentRow().setAttribute("TotalConsumption",totalConsumption);  

    }

Step 4:

 Now Add Method (perBatchConsVCLstnrBind) in AM


Step 5:

After Add Method into AM, you also need to add into ADF Page(where you are performing your calculation)


Step 6:

Finally run the application and look the action on field when you change it



No comments:

Thank you for your comment...!

Powered by Blogger.