Search This Blog

ADF - Display value based on selection in LOV

I have a form with 2 fields, Severity and Priority. User will select a value from Severity LOV, and based on the value selected, Priority will get its value.

The problem is when I am saving the form, only the Severity value gets saved in the database, while Priority is set to null, even though I can see the Priority value displayed on the screen while selecting from Severity LOV in the form.

Bind the valueChangeListener property of the LOV with valueChanged method. This is the code of the method:

    public void valueChanged(ValueChangeEvent valueChangeEvent) {
        //The selected value doesn't get updated to the model by the time ValueChangeListener gets 
        //invoked. This will update the model
        JSFUtils.setExpressionValue("#{bindings.Severity.inputValue}", valueChangeEvent.getNewValue());
        Object selectedValue = JSFUtils.resolveExpression("#{bindings.Severity.attributeValue}");
        System.out.println("selectedValue: " + selectedValue.toString());
        String priority = null;
        if (selectedValue.equals("MINOR")) {
            priority = "LOW";
        } else if (selectedValue.equals("FATAL")) {
            priority = "HIGH";
        } else if (selectedValue.equals("MAJOR")) {
            priority = "NORMAL";
        }
        System.out.println("priority: " + priority);
        JSFUtils.setExpressionValue("#{bindings.Priority.inputValue}", priority);
    }

ADF - Programatically Applying and Creating View Criteria

CASE 1: I have already created a view criteria in EmployeeVO, and I want to call it programmatically.
 
public void searchEmployee(Number employeeId) {
        ViewObjectImpl vo = getEmployeesView1();
        ViewCriteria vc = vo.getViewCriteria("findEmployeeVC");
        vo.applyViewCriteria(vc);
        vo.setNamedWhereClauseParam("pEmployeeId", employeeId);
        vo.executeQuery();
    }


CASE 2: I want to create a view criteria dynamically and execute it programmatically.


    public void searchByEmployeeIdEmail(Number employeeId, String email) {
        ViewObjectImpl vo = getEmployeesView2();
        ViewCriteria vc = vo.createViewCriteria();
        ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
        
        vcRow.setAttribute("EmployeeId", employeeId);
        vc.addRow(vcRow);
        vcRow.setAttribute("Email", email);
        vc.addRow(vcRow);
        
        vo.applyViewCriteria(vc);
        vo.executeQuery();
    } 
 
 CASE 3: Apply ExecuteQuery() in View Layer 
 
DCBindingContainer bindings2 = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
JUCtrlHierBinding obj = (JUCtrlHierBinding)bindings2.findCtrlBinding("EmployeesEOView1");
ViewObject vo= obj.getViewObject();
vo.setNamedWhereClauseParam("BindEmployeeId",101);
vo.executeQuery(); 
  
Code to check the value in query : 
 
DCBindingContainer dcBindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dciter = dcBindings.findIteratorBinding(
EmployeesEOView1Itterator
);
RowSetIterator RowSetI = dciter.getRowSetIterator();
for (Row row : RowSetI.getAllRowsInRange()) {
System.out.println("Row : " + row);
}
RowSetI.closeRowSetIterator();
 
 
 

ADF - Populate ADF Table using managed Bean and DTO

In this use case, we will be building an employee form where the user will enter details and then click on Save. Once the data is saved, the results will be displayed in the table below.



For every field displayed on the form, we need to declare a variable in the managed bean, and create getters setters.
    private String firstName;
    private String lastName;
    private String email;
    private Date hireDate;
    private String jobID;

Now for every inputField, bind the value property with the variable defined. For example, for the First Name field, I have set the value property as #{pageFlowScope.myBean.firstName}.
This is the method defined in the managed bean for the Save button:
 
 public void onClickSave(ActionEvent actionEvent) {
        // Add event code here...
        Map searchValueMap = new HashMap();
        searchValueMap.put(FIRST_NAME, firstName);
        searchValueMap.put(LAST_NAME, lastName);
        searchValueMap.put(EMAIL, email);
        searchValueMap.put(HIRE_DATE, hireDate);
        searchValueMap.put(JOB_ID, jobID);

        Map parameters = new HashMap();
        parameters.put("params", searchValueMap);

        BindingContainer bindings = getBindings();
        OperationBinding operationBinding =
            bindings.getOperationBinding("saveEmployee");
        operationBinding.getParamsMap().putAll(parameters);
        emplist = (List)operationBinding.execute();

        AdfFacesContext.getCurrentInstance().addPartialTarget(empTable);
    }

This is from the Application module:


    public List saveEmployee(Map params) { 
 
        ViewObjectImpl vo = getEmployeesView1();
        ViewRowImpl vor = (ViewRowImpl)vo.createRow();
        getEmployeesView1().insertRow(vor);
        //vor.setAttribute("EmployeeId", params.get("employeeID"));
        vor.setAttribute("FirstName", params.get("firstName"));
        vor.setAttribute("LastName", params.get("lastName"));
        vor.setAttribute("Email", params.get("email"));
        vor.setAttribute("HireDate", params.get("hireDate"));
        vor.setAttribute("JobId", params.get("jobID"));
        vor.getApplicationModule().getTransaction().commit();

        vo.executeQuery();
        
        List employeeList = null;
        EmployeeDTO employeeDTO = null;
        
        RowSet rowSet = vo.getRowSet();
        Row row = null;
        if (null != rowSet) {
            employeeList = new ArrayList();
            row = rowSet.first();
            while (null != row) {
                employeeDTO = getEmployeeDTOFromRow(row);
                employeeList.add(employeeDTO);
                row = rowSet.next();
            }
        }
        return employeeList;
    }
    
    private EmployeeDTO getEmployeeDTOFromRow(Row row) {
        EmployeeDTO employeeDTO = new EmployeeDTO();
        employeeDTO.setEmployeeID((Number)row.getAttribute("EmployeeId"));
        employeeDTO.setFirstName((String)row.getAttribute("FirstName"));
        employeeDTO.setLastName((String)row.getAttribute("LastName"));
        employeeDTO.setEmail((String)row.getAttribute("Email"));
        employeeDTO.setHireDate((Date)row.getAttribute("HireDate"));
        employeeDTO.setJobID((String)row.getAttribute("JobId"));
        return employeeDTO;
    }

For the table, I have set the value property as #{pageFlowScope.myBean.emplist} and binding property as #{pageFlowScope.myBean.empTable}. Getters and setters are created for both:
 
    private RichTable empTable;

    private List emplist;