Saturday, April 14, 2012

Project Gantt Chart in Adf (Version 2)

Hi ,

As my last post i had posted the basis explanation of Gantt Chart in adf.In this post i will try to explain the creation of the new Task Type and apply those newly created task type in to Project Gantt Chart task.

And same time i also want to incorporate the following point on GanttChartProjectBean class which is  maintained on oracle site 

Under section 26.2.1 Data for a Project Gantt Chart

"Optionally, the object could implement the oracle.adf.view.faces.bi.model.Task interface to ensure it provides the correct properties to the Gantt chart."

i have implemented the Task interface on the GanttChartProjectBean class.

Code is following
package com.prateek.oracle.adf.view.bean;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import oracle.adf.view.faces.bi.model.Dependency;
import oracle.adf.view.faces.bi.model.RecurringTask;
import oracle.adf.view.faces.bi.model.SplitTask;
import oracle.adf.view.faces.bi.model.Task;


public class GanttChartProjectBean implements Task {

    public GanttChartProjectBean() {
    }
    // Date. The actual end time for normal and milestone tasks.
    private Date actualEnd;
    //Date. The actual start time for normal and milestone tasks.
    private Date actualStart;
    //Date. Completed through for normal and summary tasks.
    private Date completedThrough;
    //Boolean. Specifies whether or not the task is critical for all tasks.
    private Boolean critical;
    //A list of dependencies for a task. Data object keys for dependencies include:
    //       fromId: The ID of the task where the dependency begins.
    //       toId: The ID of the task where the dependency ends.
    //       type: The type of the dependency. Valid values are start-start, start-finish, finish-finish, finish-start, start-before, start-together, finish-after, and finish-together.
    //  Dependency (node)
    //Date. The end time for all tasks.    (required)
    private Date endTime;
    //String. The first icon associated with the task bar for all tasks.
    //The icon might change depending on other attributes
    private String icon1;
    //String. The second icon associated with the tasks bar for all tasks.
    private String icon2;
    //String. The third icon associated with the tasks bar for all tasks.
    private String icon3;
    //String. The alignment of the icon in the task bar for all tasks. Valid values are left (default),
    //right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String iconPlacement;
    //Boolean. Specifies whether or not a node definition is a container.
    private Boolean isContainer;
    //String. The label associated with the task bar for all tasks.
    private String label;
    //String. The alignment of the label in the task bar for all tasks. Valid values are left (default), right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String labelPlacement;
    //Integer. Percentage completed for normal and summary tasks.
    private Integer percentComplete;
    //  Recurring tasks (node)
    //  The list of recurring tasks for all tasks.
    //  Split tasks (node)
    //  The list of tasks without a continuous time line for all tasks.
    //Date. The starting time for all tasks.(required)
    private Date startTime;
    //  Subtasks (node)
    //  An optional list of subtasks for all tasks.
    //String. The unique identifier for all tasks.
    private String taskId;
    //Sting. The type of the tasks for all tasks.
    private String type;
    //not in the documnet but still adding because gantt is throwing exception
    private String taskType;
    //split task
    private List<SplitTask> splitTasks;
    private List<Dependency> dependencies;
    private List<RecurringTask> recurringTask;
    private String recurringTaskId;

    public void setActualEnd(Date actualEnd) {
        this.actualEnd = actualEnd;
    }

    public Date getActualEnd() {
        return actualEnd;
    }

    public void setActualStart(Date actualStart) {
        this.actualStart = actualStart;
    }

    public Date getActualStart() {
        return actualStart;
    }

    public void setCompletedThrough(Date completedThrough) {
        this.completedThrough = completedThrough;
    }

    public Date getCompletedThrough() {
        return completedThrough;
    }

    public void setCritical(Boolean critical) {
        this.critical = critical;
    }

    public Boolean getCritical() {
        return critical;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setIcon1(String icon1) {
        this.icon1 = icon1;
    }

    public String getIcon1() {
        return icon1;
    }

    public void setIcon2(String icon2) {
        this.icon2 = icon2;
    }

    public String getIcon2() {
        return icon2;
    }

    public void setIcon3(String icon3) {
        this.icon3 = icon3;
    }

    public String getIcon3() {
        return icon3;
    }

    public void setIconPlacement(String iconPlacement) {
        this.iconPlacement = iconPlacement;
    }

    public String getIconPlacement() {
        return iconPlacement;
    }

    public void setIsContainer(Boolean isContainer) {
        this.isContainer = isContainer;
    }

    public Boolean getIsContainer() {
        return isContainer;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public void setLabelPlacement(String labelPlacement) {
        this.labelPlacement = labelPlacement;
    }

    public String getLabelPlacement() {
        return labelPlacement;
    }

    public void setPercentComplete(Integer percentComplete) {
        this.percentComplete = percentComplete;
    }

    public Integer getPercentComplete() {
        return percentComplete;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getTaskType() {
        return taskType;
    }

    public String toString() {
        return taskId;
    }

    public int getLabelAlign() {
        return 0;
    }

    public int getIconAlign() {
        return 0;
    }

    public List<RecurringTask> getRecurringTasks() {
        return Collections.emptyList();
    }

    public void setSplitTasks(List<SplitTask> splitTasks) {
        this.splitTasks = splitTasks;
    }

    public List<SplitTask> getSplitTasks() {
        return splitTasks;
    }

    public void setDependencies(List<Dependency> dependencies) {
        this.dependencies = dependencies;
    }

    public List<Dependency> getDependencies() {
        return dependencies;
    }

    public void setRecurringTaskId(String recurringTaskId) {
        this.recurringTaskId = recurringTaskId;
    }

    public String getRecurringTaskId() {
        return recurringTaskId;
    }

    public void setRecurringTask(List<RecurringTask> recurringTask) {
        this.recurringTask = recurringTask;
    }

    public List<RecurringTask> getRecurringTask() {
        return recurringTask;
    }
}

Creating a New Task Type :

Using Task Bar  Format we can customize the bar which is render in the chart region of the Gantt Chart.
Task Bat Format  contains following properties 
 

1-Fill color
2-Fill image pattern
3-Border color
4-Images used for a milestone task
5-Images used for the beginning and end of a summary task

we can override these properties according over business requirement and create new task.


I have created the a method in Utils class which we will create new type of the task and  it will register the newly created task in Task Bar Manager .However in backing bean we need to apply  newly created task type to Task using setTaskType method.

Code is following :

     public static void createNewTask(TaskbarFormatManager taskbarFormatManager,
                                     String taskName) {
        TaskbarFormat taskbarFormat = null;
        if (taskName.equals(GanttChartConstantsBean.NEW_TASK_CANCELED)) {
            taskbarFormat =
                    new TaskbarFormat(taskName, GanttChartConstantsBean.CANCELED_TASK_COLOR_HEXADECIMAL_VALUE,
                                      GanttChartConstantsBean.NULL,
                                      GanttChartConstantsBean.CANCELED_TASK_COLOR_HEXADECIMAL_VALUE,
                                      GanttChartConstantsBean.HEIGHT);
        } else if (taskName.equals(GanttChartConstantsBean.NEW_TASK_COMPLETE)) {
            taskbarFormat =
                    new TaskbarFormat(taskName, GanttChartConstantsBean.COMPLETE_TASK_COLOR_HEXADECIMAL_VALUE,
                                      GanttChartConstantsBean.NULL,
                                      GanttChartConstantsBean.COMPLETE_TASK_COLOR_HEXADECIMAL_VALUE,
                                      GanttChartConstantsBean.HEIGHT);
        } else if (taskName.equals(GanttChartConstantsBean.NEW_TASK_INVALID)) {
            taskbarFormat =
                    new TaskbarFormat(taskName, GanttChartConstantsBean.INVALID_TASK_COLOR_INVALID_VALUE,
                                      GanttChartConstantsBean.NULL,
                                      GanttChartConstantsBean.INVALID_TASK_COLOR_INVALID_VALUE,
                                      GanttChartConstantsBean.HEIGHT);
        } else {
            //No need to do any things
        }
        taskbarFormatManager.registerTaskbarFormat(taskName, taskbarFormat);
    }

 

In this class i have created three different type of task which  are

1-Canceled
2-Complete
3-Invalid

On the basis of user requirement ,developer should have to pass the current instance of taskbarFormatManager Object and type of task it's  may be any one of three of them  .

If you apply the Invalid Task it will look like  following :


If you apply the CANCELED Task it will look like  following :
 If you apply the COMPLETE Task it will look like  following :
The following code is used to create the new task and applying the newly task type on task

            ganttChartProjectBean.setCritical(false);
            ganttChartProjectBean.setEndTime(GanttChartUtil.addMonth(3));
            ganttChartProjectBean.setStartTime(GanttChartUtil.addMonth(1));
            ganttChartProjectBean.setTaskId("1");
            ganttChartProjectBean.setType("firstwork");
            ganttChartProjectBean.setLabel("Project One");
            ganttChartProjectBean.setTaskType("Normal");
            ganttChartProjectBean.setLabelPlacement("end");
            ganttChartProjectBean.setIconPlacement("right");
            GanttChartUtil.createNewTask(_ganttChartBinding.getTaskbarFormatManager(),
                                         GanttChartConstantsBean.NEW_TASK_INVALID);
            ganttChartProjectBean.setTaskType(GanttChartConstantsBean.NEW_TASK_INVALID);



*I am still on working on the Model(GanttChartProjectBean) class to make it generic.


Download project from following link

http://www.4shared.com/rar/4JAz5xfQ/GanttChartV20.html


Thanks
Prateek Shaw

Sunday, April 8, 2012

Gantt Chart in adf (Version 1.0)

Gantt Chart :

Gantt Chart is pictorial representation of the data.indeed it is not an easy task to create the Gantt Chart through  EJB business service.

The following definition of  Gantt Chart is  present at oracle site .

"A Gantt chart is a type of horizontal bar graph that you use to plan and track projects. It shows resources or tasks in a time frame with a distinct beginning and end. An ADF Gantt chart component is composed of two regions, one displaying the Gantt chart data in a table, and the other displaying the Gantt chart data graphically with a resizable splitter between the two regions. The table and chart regions share the same data and selection model, supporting and synchronizing scrolling, and expanding and collapsing of rows between the two regions.
At runtime, Gantt charts provide interaction capabilities in the table region to the user such as entering data, expanding and collapsing rows, showing and hiding columns, navigating to a row, and sorting and totaling columns. In the chart region, users can drag a task to a new date, select multiple tasks to create dependencies, and extend the task date. A Gantt chart toolbar is available to support user operations such as changing or filtering the view of the data, and creating, deleting, cutting, copying, and pasting tasks.
Both Gantt chart regions are based on an ADF Faces tree table component."

Basically oracle is supporting follwing three type of gantt chart
1-Project Gantt chart
2-Resource Utilization Gantt chart
3-Scheduling Gantt chart

BTW Gantt Chart contains following  two part.

 1-Table Region -This part  will show the task information in tabular form.This is render the same as af:table therefore it has same behavior.
 which af:table has.it part contains atleast one column.
 2-Gantt Region:This will show the the gantt chart of the data with more other information

 Gantt Chart task is following flavor :
here i just copy paste material whatever is presant in oracle (no comments same as oracle site :)
 1-Normal :The basic task type. It is a plain horizontal bar that shows the start time, end time, and duration of the task.)
 2-Summary: The start and end date for a group of subtasks.
 A summary task cannot be moved or extended. Instead,
 it is the responsibility of the application to execute code to recalculate the start and end date for a summary task when the date of a subtask changes. Summary tasks are available only for the project Gantt chart.
3-Milestone: A specific date in the Gantt chart. There is only one date associated with a milestone task.
A milestone task cannot be extended but it can be moved. A milestone task is available only for the project Gantt chart.
4-Recurring: A task that is repeated in a Gantt chart, each instance with its own start and end date.
Individual recurring tasks can optionally contain a subtype. All other properties of the individual recurring tasks come from the task which they are part of. However, if an individual recurring task has a subtype, this subtype overrides the task type.
5-Split: A task that is split into two horizontal bars, usually linked by a line. The time between the bars represents idle time due to traveling or down time.
6-Scheduled: The basic task type for a scheduling Gantt chart. This task type shows the starting time, ending time, and duration of a task, as well as startup time if one is specified.


IN this post i am going to share you how to create the Project gantt chart.

First following tag is use for creating the Project Gantt

 <dvt:projectGantt endTime="#{pageFlowScope.ganttChart._endDate}"
                          startTime="#{pageFlowScope.ganttChart._startDate}"
                          var="task"
                          filterManager="#{pageFlowScope.filterManagerGanttChart.addFilter}"
                          value="#{pageFlowScope.ganttChart._ganttChartModel}"
                          filterListener="#{pageFlowScope.ganttChart.newFilter}"
                          binding="#{pageFlowScope.ganttChart._ganttChartBinding}"
                          horizontalGridVisible="false" tooltipKeyLabels="Hello"
                          summary="This is Testing Project"
                          initiallyExpandAll="false">
          <f:facet name="major">
            <dvt:timeAxis scale="months"/>
          </f:facet>
          <f:facet name="minor">
            <dvt:timeAxis scale="weeks"/>
          </f:facet>
          <f:facet name="nodeStamp">
            <af:column headerText="Task Id" filterable="true">
              <af:outputText value="#{task.taskId}"/>
            </af:column>
          </f:facet>
          <af:column headerText="Task Name" filterable="true">
            <af:outputText value="#{task.type}"/>
          </af:column>
 </dvt:projectGantt>


 value attribute will  take TreeModel model object.

 For creating the Project Gantt  we required the class which look like following class

package com.prateek.oracle.adf.view.bean;

import com.prateek.oracle.adf.view.bean.DependencyTask;

import com.prateek.oracle.adf.view.bean.SplitTasksBean;

import java.util.Date;
import java.util.List;


public class GanttChartProjectBean {

    public GanttChartProjectBean() {
    }
    // Date. The actual end time for normal and milestone tasks.
    private Date actualEnd;
    //Date. The actual start time for normal and milestone tasks.
    private Date actualStart;
    //Date. Completed through for normal and summary tasks.
    private Date completedThrough;
    //Boolean. Specifies whether or not the task is critical for all tasks.
    private Boolean critical;
    //A list of dependencies for a task. Data object keys for dependencies include:
    //       fromId: The ID of the task where the dependency begins.
    //       toId: The ID of the task where the dependency ends.
    //       type: The type of the dependency. Valid values are start-start, start-finish, finish-finish, finish-start, start-before, start-together, finish-after, and finish-together.
    //  Dependency (node)
    //Date. The end time for all tasks.    (required)
    private Date endTime;
    //String. The first icon associated with the task bar for all tasks.
    //The icon might change depending on other attributes
    private String icon1;
    //String. The second icon associated with the tasks bar for all tasks.
    private String icon2;
    //String. The third icon associated with the tasks bar for all tasks.
    private String icon3;
    //String. The alignment of the icon in the task bar for all tasks. Valid values are left (default),
    //right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String iconPlacement;
    //Boolean. Specifies whether or not a node definition is a container.
    private Boolean isContainer;
    //String. The label associated with the task bar for all tasks.
    private String label;
    //String. The alignment of the label in the task bar for all tasks. Valid values are left (default), right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String labelPlacement;
    //Integer. Percentage completed for normal and summary tasks.
    private Integer percentComplete;
    //  Recurring tasks (node)
    //  The list of recurring tasks for all tasks.
    //  Split tasks (node)
    //  The list of tasks without a continuous time line for all tasks.
    //Date. The starting time for all tasks.(required)
    private Date startTime;
    //  Subtasks (node)
    //  An optional list of subtasks for all tasks.
    //String. The unique identifier for all tasks.
    private String taskId;
    //Sting. The type of the tasks for all tasks.
    private String type;
    //not in the documnet but still adding because gantt is throwing exception
    private String taskType;
    //split task
    private List<SplitTasksBean> splitTasks;
    private List<DependencyTask> dependencies;


    public void setActualEnd(Date actualEnd) {
        this.actualEnd = actualEnd;
    }

    public Date getActualEnd() {
        return actualEnd;
    }

    public void setActualStart(Date actualStart) {
        this.actualStart = actualStart;
    }

    public Date getActualStart() {
        return actualStart;
    }

    public void setCompletedThrough(Date completedThrough) {
        this.completedThrough = completedThrough;
    }

    public Date getCompletedThrough() {
        return completedThrough;
    }

    public void setCritical(Boolean critical) {
        this.critical = critical;
    }

    public Boolean getCritical() {
        return critical;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setIcon1(String icon1) {
        this.icon1 = icon1;
    }

    public String getIcon1() {
        return icon1;
    }

    public void setIcon2(String icon2) {
        this.icon2 = icon2;
    }

    public String getIcon2() {
        return icon2;
    }

    public void setIcon3(String icon3) {
        this.icon3 = icon3;
    }

    public String getIcon3() {
        return icon3;
    }

    public void setIconPlacement(String iconPlacement) {
        this.iconPlacement = iconPlacement;
    }

    public String getIconPlacement() {
        return iconPlacement;
    }

    public void setIsContainer(Boolean isContainer) {
        this.isContainer = isContainer;
    }

    public Boolean getIsContainer() {
        return isContainer;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public void setLabelPlacement(String labelPlacement) {
        this.labelPlacement = labelPlacement;
    }

    public String getLabelPlacement() {
        return labelPlacement;
    }

    public void setPercentComplete(Integer percentComplete) {
        this.percentComplete = percentComplete;
    }

    public Integer getPercentComplete() {
        return percentComplete;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setDependencies(List<DependencyTask> dependencyTaskList) {
        this.dependencies = dependencyTaskList;
    }

    public List<DependencyTask> getDependencies() {
        return dependencies;
    }

    public void setSplitTasks(List<SplitTasksBean> splitTaskList) {
        this.splitTasks = splitTaskList;
    }

    public List<SplitTasksBean> getSplitTasks() {
        return splitTasks;
    }

}

For getting the TreeModel  object i have written the following code :

    public TreeModel get_ganttChartModel() {
        if (_ganttChartModel == null) {
            List<GanttChartProjectBean> projectList =
                new ArrayList<GanttChartProjectBean>();
            GanttChartProjectBean ganttChartProjectBean =
                new GanttChartProjectBean();
            ganttChartProjectBean.setCritical(false);
            ganttChartProjectBean.setEndTime(GanttChartUtil.addMonth(3));
            ganttChartProjectBean.setStartTime(GanttChartUtil.addMonth(3));
            ganttChartProjectBean.setTaskId("1");
            ganttChartProjectBean.setType("firstwork");
            ganttChartProjectBean.setLabel("Project One ");
            ganttChartProjectBean.setTaskType("Normal");
            ganttChartProjectBean.setLabelPlacement("end");
            ganttChartProjectBean.setPercentComplete(10);
            projectList.add(ganttChartProjectBean);
            _ganttChartModel = new ChildPropertyTreeModel(projectList, null);

        }
        return _ganttChartModel;
    }


   * Here in this method i have just creating the dummy records hence any one can  put their own business logic it may be getting the records from table or using EIB service .


You have option to over ride the default taskbarFormatManager and provide your own custom color and other type of information.


Please open the link to download the whole project

http://www.4shared.com/rar/jAeWL0x1/GanttChart.html

Thanks
Prateek

Sunday, April 1, 2012

How to create dependent LOV in adf with EJB as business component

Hi,

In this post i will explain you how to create the dependent LOV  in adf where we have EJB as business component.

Pre-Requirement :
   1-Software :jdeveloper 11.1.1.4  IDE
   2-knowledge:basic knowledge of EJB 3.0 ,ADF faces and java

Step 1:create the new project  ,select the java EE application .
Step 2:In model layer (project )create the Entity  from table
Step3:Create the Entity of the Employees and Departments table.
Step4:Add one new named query in the Employee Entity Class
         Employee class code is following




package com.prateek.oracle.adf.model.entity;

import java.io.Serializable;

import java.sql.Timestamp;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@NamedQueries( { @NamedQuery(name = "findAllEmployee",
                             query = "select o from Employee o"),
                 @NamedQuery(name = "findEmployeeById",
                             query = "select o from Employee o where o.employeeId=:empId") })
@Table(name = "EMPLOYEES")
public class Employee implements Serializable {
    @Column(name = "COMMISSION_PCT")
    private Double commissionPct;
    @Column(nullable = false, unique = true, length = 25)
    private String email;
    @Id
    @Column(name = "EMPLOYEE_ID", nullable = false)
    private Long employeeId;
    @Column(name = "FIRST_NAME", length = 20)
    private String firstName;
    @Column(name = "HIRE_DATE", nullable = false)
    private Timestamp hireDate;
    @Column(name = "JOB_ID", nullable = false, length = 10)
    private String jobId;
    @Column(name = "LAST_NAME", nullable = false, length = 25)
    private String lastName;
    @Column(name = "PHONE_NUMBER", length = 20)
    private String phoneNumber;
    private Double salary;
    @ManyToOne
    @JoinColumn(name = "MANAGER_ID")
    private Employee employee;
    @OneToMany(mappedBy = "employee")
    private List<Employee> employeeList;
    @OneToMany(mappedBy = "employee")
    private List<Department> departmentList;
    @ManyToOne
    @JoinColumn(name = "DEPARTMENT_ID")
    private Department department;

    public Employee() {
    }

    public Employee(Double commissionPct, Department department, String email,
                    Long employeeId, String firstName, Timestamp hireDate,
                    String jobId, String lastName, Employee employee,
                    String phoneNumber, Double salary) {
        this.commissionPct = commissionPct;
        this.department = department;
        this.email = email;
        this.employeeId = employeeId;
        this.firstName = firstName;
        this.hireDate = hireDate;
        this.jobId = jobId;
        this.lastName = lastName;
        this.employee = employee;
        this.phoneNumber = phoneNumber;
        this.salary = salary;
    }

    public Double getCommissionPct() {
        return commissionPct;
    }

    public void setCommissionPct(Double commissionPct) {
        this.commissionPct = commissionPct;
    }


    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Long getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(Long employeeId) {
        this.employeeId = employeeId;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public Timestamp getHireDate() {
        return hireDate;
    }

    public void setHireDate(Timestamp hireDate) {
        this.hireDate = hireDate;
    }

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }


    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public List<Employee> getEmployeeList() {
        return employeeList;
    }

    public void setEmployeeList(List<Employee> employeeList) {
        this.employeeList = employeeList;
    }

    public Employee addEmployee(Employee employee) {
        getEmployeeList().add(employee);
        employee.setEmployee(this);
        return employee;
    }

    public Employee removeEmployee(Employee employee) {
        getEmployeeList().remove(employee);
        employee.setEmployee(null);
        return employee;
    }

    public List<Department> getDepartmentList() {
        return departmentList;
    }

    public void setDepartmentList(List<Department> departmentList) {
        this.departmentList = departmentList;
    }

    public Department addDepartment(Department department) {
        getDepartmentList().add(department);
        department.setEmployee(this);
        return department;
    }

    public Department removeDepartment(Department department) {
        getDepartmentList().remove(department);
        department.setEmployee(null);
        return department;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public String toString() {
        return employeeId + firstName + lastName;
    }
}

Department Entity class is following


package com.prateek.oracle.adf.model.entity;

import java.io.Serializable;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@NamedQueries({
@NamedQuery(name = "Department.findAll", query = "select o from Department o")
})
@Table(name = "DEPARTMENTS")
public class Department implements Serializable {
@Id
@Column(name="DEPARTMENT_ID", nullable = false)
private Long departmentId;
@Column(name="DEPARTMENT_NAME", nullable = false, length = 30)
private String departmentName;
@Column(name="LOCATION_ID")
private Long locationId;
@ManyToOne
@JoinColumn(name = "MANAGER_ID")
private Employee employee;
@OneToMany(mappedBy = "department")
private List employeeList;

public Department() {
}

public Department(Long departmentId, String departmentName,
Long locationId, Employee employee) {
this.departmentId = departmentId;
this.departmentName = departmentName;
this.locationId = locationId;
this.employee = employee;
}

public Long getDepartmentId() {
return departmentId;
}

public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}

public String getDepartmentName() {
return departmentName;
}

public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}

public Long getLocationId() {
return locationId;
}

public void setLocationId(Long locationId) {
this.locationId = locationId;
}


public Employee getEmployee() {
return employee;
}

public void setEmployee(Employee employee) {
this.employee = employee;
}

public List getEmployeeList() {
return employeeList;
}

public void setEmployeeList(List employeeList) {
this.employeeList = employeeList;
}

public Employee addEmployee(Employee employee) {
getEmployeeList().add(employee);
employee.setDepartment(this);
return employee;
}

public Employee removeEmployee(Employee employee) {
getEmployeeList().remove(employee);
employee.setDepartment(null);
return employee;
}

public String toString() {
return departmentId +departmentName ;
}
}


Step5:Create the Session Bean and add all the method  both Entity class
Step6:Code will as following


package com.prateek.oracle.adf.sessionbean;

import com.prateek.oracle.adf.model.entity.Department;

import com.prateek.oracle.adf.model.entity.Employee;

import java.util.List;

import javax.ejb.Stateless;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless(name = "SessionEJB", mappedName = "DependentLOVINEJB-Model-SessionEJB")
public class SessionEJBBean implements SessionEJB, SessionEJBLocal {
    @PersistenceContext(unitName="Model")
    private EntityManager em;

    public SessionEJBBean() {
    }

    public Object queryByRange(String jpqlStmt, int firstResult,
                               int maxResults) {
        Query query = em.createQuery(jpqlStmt);
        if (firstResult > 0) {
            query = query.setFirstResult(firstResult);
        }
        if (maxResults > 0) {
            query = query.setMaxResults(maxResults);
        }
        return query.getResultList();
    }

    public Department persistDepartment(Department department) {
        em.persist(department);
        return department;
    }

    public Department mergeDepartment(Department department) {
        return em.merge(department);
    }

    public void removeDepartment(Department department) {
        department = em.find(Department.class, department.getDepartmentId());
        em.remove(department);
    }

    /** <code>select o from Department o</code> */
    public List<Department> getDepartmentFindAll() {
        return em.createNamedQuery("Department.findAll").getResultList();
    }

    public Employee persistEmployee(Employee employee) {
        em.persist(employee);
        return employee;
    }

    public Employee mergeEmployee(Employee employee) {
        return em.merge(employee);
    }

    public void removeEmployee(Employee employee) {
        employee = em.find(Employee.class, employee.getEmployeeId());
        em.remove(employee);
    }

    /** <code>select o from Employee o</code> */
    public List<Employee> getEmployeeFindAll() {
        return em.createNamedQuery("Employee.findAll").getResultList();
    }

    /** <code>select o from Employee o</code> */
    public List<Employee> findAllEmployee() {
        return em.createNamedQuery("findAllEmployee").getResultList();
    }

    /** <code>select o from Employee o where o.employeeId=:empId</code> */
    public List<Employee> findEmployeeById(Long empId) {
        return em.createNamedQuery("findEmployeeById").setParameter("empId", empId).getResultList();
    }
}

findAllEmployee and findEmployeeById method i am going to use in jspx page to create the select one choice of Employee and Department Entity.

Step 7:create the backing bean which contains following code :



package com.prateek.oracle.adf.view.backingbean;

import com.prateek.oracle.adf.model.entity.Department;

import com.prateek.oracle.adf.model.entity.Employee;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.view.rich.context.AdfFacesContext;

import oracle.binding.OperationBinding;

public class ExampleBean {
    //it is used to create the select one chioce of the employee
    private List<SelectItem> employeeList;
    //it is used to create the select one choice of the department
    private List<SelectItem> departmentList;
    //employee id will hold the select employee id in jspx page
    private Long employeeId;
    //department id will hold the select department id in jspx page.
    private Long departmentId;


    public void setEmployeeList(List<SelectItem> employeeList) {
        this.employeeList = employeeList;
    }

    public List<SelectItem> getEmployeeList() {
        if (employeeList == null) {
            FacesContext context = FacesContext.getCurrentInstance();
            Application app = context.getApplication();
            DCBindingContainer bindings =
                (DCBindingContainer)app.getVariableResolver().resolveVariable(context,
                                                                              "bindings");
            List<Employee> employee = new ArrayList<Employee>();
            OperationBinding operationBinding =
                bindings.getOperationBinding("findAllEmployee");
            employee = (List<Employee>)operationBinding.execute();
            if (operationBinding.getErrors().isEmpty()) {
                employeeList = new ArrayList<SelectItem>();
                for (Employee employeeValue : employee) {
                    employeeList.add(new SelectItem(employeeValue.getEmployeeId(),
                                                    employeeValue.toString()));
                }
            }
        }
        return employeeList;
    }

    public void setEmployeeId(Long employeeId) {
        this.employeeId = employeeId;
    }

    public Long getEmployeeId() {
        return employeeId;
    }


    public void setDepartmentList(List<SelectItem> departmentList) {
        this.departmentList = departmentList;
    }

        public List<SelectItem> getDepartmentList() {
        if (employeeId != null) {
            Department departmentNew =null;
            FacesContext context = FacesContext.getCurrentInstance();
            Application app = context.getApplication();
            DCBindingContainer bindings =
                (DCBindingContainer)app.getVariableResolver().resolveVariable(context,
                                                                              "bindings");
            List<Employee> employee = new ArrayList<Employee>();

            AdfFacesContext.getCurrentInstance().getPageFlowScope().put("empId",
                                                                        employeeId);
            OperationBinding operationBinding =
                bindings.getOperationBinding("findEmployeeById");
            employee = (List<Employee>)operationBinding.execute();
            Employee exam = employee.get(0);
            departmentNew = exam.getDepartment();
            if (operationBinding.getErrors().isEmpty()) {
                departmentList = new ArrayList<SelectItem>();
                    departmentList.add(new SelectItem(departmentNew.getDepartmentId(),
                                                      departmentNew.toString()));
            }
        }
        return departmentList;
    }

    public void employeeList(ValueChangeEvent valueChangeEvent) {

    }

    public void setDepartmentId(Long departmentId) {
        this.departmentId = departmentId;
    }

    public Long getDepartmentId() {
        return departmentId;
    }
}

Step 8:Create the jspx page which contains the following code



<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:form id="f1">
      <af:selectOneChoice  id="se1" value="#{viewScope.exampleBean.employeeId}" label="Empolyee List"
                         autoSubmit="true" valueChangeListener="#{viewScope.exampleBean.employeeList}">
      <f:selectItems value="#{viewScope.exampleBean.employeeList}" id="tr1"></f:selectItems>
      </af:selectOneChoice>
      <af:selectOneChoice  id="se2" value="#{viewScope.exampleBean.departmentId}" label="Department List" partialTriggers="se1"
                         autoSubmit="true" >
      <f:selectItems value="#{viewScope.exampleBean.departmentList}" id="tr2"></f:selectItems>
      </af:selectOneChoice>
     
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

Step 9:we are creating the jspx manually.means right now we do not have any page def page for this page.just right click the page and click on go to page def file.it will be automatically created the page  def file .




Step 10:add this two method in the page def file because in backing bean we are using this method which are
   1-findAllEmployee
   2-findEmployeeById

Step 11:Also do not forget to add the Backing bean into the adfc-config.xml in view scope.


I know what ever i have written in this post that is not enough to understand the whole logic but believe  me i do not have enough time to explain in depth.


Please open the link to download the example application

http://www.4shared.com/rar/AS9i31ak/DependentLOVINEJB.html

Thanks






Accesing the Binding inside in Backing Bean

Hi ,

It is very common question in Oracle ADF technology that how to access the Binding Container inside backing bean.

 we have two way to resolve this issue .

First Approach :
 DCBindingContainer bindings = (DCBindingContainer) app.getVariableResolver().resolveVariable(context, "bindings");
Second would be :

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