Sunday, 27 August 2017

Oracle ADF When-Validate-Item and Search

package view;

import java.io.Serializable;

import java.util.List;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import model.service.AppModuleAMImpl;

import oracle.adf.model.BindingContainer;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.share.logging.ADFLogger;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.input.RichInputListOfValues;
import oracle.adf.view.rich.component.rich.input.RichInputText;

import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;

import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.nav.RichResetButton;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.view.rich.util.ResetUtils;

import oracle.jbo.VariableValueManager;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaManager;
import oracle.jbo.ViewObject;

import oracle.jbo.uicli.binding.JUCtrlListBinding;

import org.apache.myfaces.trinidad.component.core.input.CoreSelectOneChoice;
import org.apache.myfaces.trinidad.util.ComponentReference;

public class CustomSearchBean implements Serializable {
    private static ADFLogger _logger = ADFLogger.createADFLogger(CustomSearchBean.class);

    private Integer empIdPgBind;
    private String firstNmPgBind;
    private String emailPgBind;
    private Number salaryPgBind;
    private String JobIdPgBind;
    private CoreSelectOneChoice selectOneChoice1;

    public void setButtonResetActionListener(RichCommandButton buttonResetActionListener) {
        this.buttonResetActionListener = buttonResetActionListener;
    }

    public RichCommandButton getButtonResetActionListener() {
        return buttonResetActionListener;
    }

    public void setButtonResetByBean(RichCommandButton buttonResetByBean) {
        this.buttonResetByBean = buttonResetByBean;
    }

    public RichCommandButton getButtonResetByBean() {
        return buttonResetByBean;
    }

    public void setButtonResetButton(RichResetButton buttonResetButton) {
        this.buttonResetButton = buttonResetButton;
    }

    public RichResetButton getButtonResetButton() {
        return buttonResetButton;
    }
    private RichCommandButton buttonResetActionListener;
    private RichCommandButton buttonResetByBean;
    private RichResetButton buttonResetButton;


    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setEmpIdPgBind(Integer empIdPgBind) {
        this.empIdPgBind = empIdPgBind;
    }

    public Integer getEmpIdPgBind() {
        return empIdPgBind;
    }

    public void setFirstNmPgBind(String firstNmPgBind) {
        this.firstNmPgBind = firstNmPgBind;
    }

    public String getFirstNmPgBind() {
        return firstNmPgBind;
    }

    public void setEmailPgBind(String emailPgBind) {
        this.emailPgBind = emailPgBind;
    }

    public String getEmailPgBind() {
        return emailPgBind;
    }

    public void setSalaryPgBind(Number salaryPgBind) {
        this.salaryPgBind = salaryPgBind;
    }

    public Number getSalaryPgBind() {
        return salaryPgBind;
    }

    public CustomSearchBean() {
    }

    public Object resolvElDC(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp =
            elFactory.createValueExpression(elContext, "#{data." + data + ".dataProvider}", Object.class);
        return valueExp.getValue(elContext);
    }

    public void searchButton(ActionEvent actionEvent) {
        AppModuleAMImpl am = (AppModuleAMImpl) resolvElDC("AppModuleAMDataControl");
        ViewObject empVo = am.getEmployees1();
        ViewCriteriaManager vcm = empVo.getViewCriteriaManager();
        ViewCriteria vc = vcm.getViewCriteria("EmployeesVOCriteria");
        VariableValueManager vvm = vc.ensureVariableManager();
        vvm.setVariableValue("EmpIdBind", getEmpIdPgBind());
        vvm.setVariableValue("FirstNmBind", getFirstNmPgBind());
        vvm.setVariableValue("EmailBind", getEmailPgBind());
        vvm.setVariableValue("SalaryBind", getSalaryPgBind());
        vvm.setVariableValue("JobIdBind", getJobIdPgBind());
        empVo.applyViewCriteria(vc);
        empVo.executeQuery();
    }

    public void resetButton(ActionEvent actionEvent) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIViewRoot root = facesContext.getViewRoot();
        ComponentReference<RichSelectOneChoice> richText2 =
            ComponentReference.newUIComponentReference((RichSelectOneChoice) root.findComponent("soc1"));
        RichSelectOneChoice inputText2 = richText2.getComponent();
        inputText2.setValue("");

        AppModuleAMImpl am = (AppModuleAMImpl) resolvElDC("AppModuleAMDataControl");
        ViewObject attrVo = am.getcustom1();
        /*
         ViewObject empVo = am.getEmployees1();
         ViewCriteriaManager vcm = empVo.getViewCriteriaManager();
         ViewCriteria vc = vcm.getViewCriteria("EmployeesVOCriteria");
         VariableValueManager vvm = vc.ensureVariableManager();
         vvm.setVariableValue("EmpIdBind", null);
         vvm.setVariableValue("FirstNmBind", null);
         vvm.setVariableValue("EmailBind", null);
         vvm.setVariableValue("SalaryBind", null);
         vvm.setVariableValue("JobIdBind", null);
         empVo.applyViewCriteria(vc);
         empVo.executeQuery();
         setEmpIdPgBind(null);
         setFirstNmPgBind(null);
         setEmailPgBind(null);
         setSalaryPgBind(null);
         setJobIdPgBind(null); */
        attrVo.executeQuery();

    }

    public void setJobIdPgBind(String JobIdPgBind) {
        this.JobIdPgBind = JobIdPgBind;
    }

    public String getJobIdPgBind() {
        return JobIdPgBind;
    }

    public void MessageDisp(ActionEvent actionEvent) {
        // Add event code here...

        /*BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding dciterContainer =
        (DCIteratorBinding)bindings.get(iteratorName);

        Row ri = dciterContainer.getRowAtRangeIndex(index);
        String val = (String)ri.getAttribute("soc1");**/
    }

    public void ClearGlobal(ActionEvent actionEvent) {
        // Add event code here...
        // check if hte action has a component attatched
        System.out.println("... Clear Global ...");
        UIComponent uiComp = actionEvent.getComponent();

        if (uiComp == null) {
            // if not we use the button which we bound to this bean
            uiComp = getButtonResetByBean();
            _logger.info("reset fields: buttonID = " + uiComp.getId());
            System.out.println("... Null  reset fields: buttonID = " + uiComp.getId());
        } else {
            _logger.info("reset fields: CompID = " + uiComp.getId());
            System.out.println("... Not Null reset fields: CompID = " + uiComp.getId());
        }
        // pass component inside the UIForm, UIXForm, UIXSubform, UIXRegion, UIXPopup, RichCarousel
        // or RichPanelCollection which holds the components to reset
        ResetUtils.reset(uiComp);

    }

    public void ChoiceList(ActionEvent actionEvent) {
        /*  // Add event code here...
        // Get the binding
            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
            // Get the sepecific list binding
            JUCtrlListBinding listBinding =
            (JUCtrlListBinding)bindings.get("DepartmentId");
            // Get the value which is currently selected
            Object selectedValue = listBinding.getSelectedValue();
            System.out.println(selectedValue);*/
    }

    public String b6_action() {
        // Add event code here...
        AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
        //resetValueInputItems(adfFacesContext, "pfl1");
        return null;
    }

    private void resetValueInputItems(AdfFacesContext adfFacesContext, UIComponent component) {
        List<UIComponent> items = component.getChildren();
        for (UIComponent item : items) {
            //resetValueInputItems(adfFacesContext,item); //uncomment in case of nested UIComponents
            if (item instanceof RichInputText) {
                RichInputText input = (RichInputText) item;
                if (!input.isDisabled()) {
                    input.resetValue();
                    adfFacesContext.addPartialTarget(input);
                }
            } else if (item instanceof RichInputDate) {
                RichInputDate input = (RichInputDate) item;
                if (!input.isDisabled()) {
                    input.resetValue();
                    input.setValue("");
                    adfFacesContext.addPartialTarget(input);
                }
            } else if (item instanceof RichSelectOneChoice) {
                RichSelectOneChoice input = (RichSelectOneChoice) item;
                if (!input.isDisabled()) {
                    input.resetValue();
                    input.setValue("");
                    adfFacesContext.addPartialTarget(input);
                }
            }
        } //end -for each loop
    }
}

No comments:

Post a Comment