Passing Variables to other pages |
Let us see how we can pass variables from one page to another which are in same ADF taskflow
basically pass variable from page1 to page2
We will create MyBean.java and In the adf-config.xml under Managed bean , this variable is to be set to pageFlow Scope
package view; public class MyBean { private String username; public void setUsername(String username) { this.username = username; } public String getUsername() { return username; } public MyBean() { } }
Map the variable value of textbox to the username in the bean as shown below
we can now retrieve back the value in another page
The Input will be
t will be as shown below.
Static Data Controls |
Sometimes we would need Java based static data control, which could be used to display forms / static data or even graphs .. infact once you have logic for static Java Data controls , the data you can get from other sources like webservices / procedures / sql .. the UI layer can still be the same. To do that let us create 2 static java classes Employee Data Model and Employee Data The Employee Data Model class will have getter and setter methods , similar to database column names, in the constructor we will populate all these variables.
package view; import java.util.Date; public class EmpDataModel { private int empId; private String empName; private String empDept; private int empSalary; private Date empDob; public EmpDataModel(int empId, String empName, String empDept, int empSalary, Date empDob) { this.empId = empId; this.empName = empName; this.empDept = empDept; this.empSalary = empSalary; this.empDob = empDob; } public void setEmpId(int empId) { this.empId = empId; } public int getEmpId() { return empId; } public void setEmpName(String empName) { this.empName = empName; } public String getEmpName() { return empName; } public void setEmpDept(String empDept) { this.empDept = empDept; } public String getEmpDept() { return empDept; } public void setEmpSalary(int empSalary) { this.empSalary = empSalary; } public int getEmpSalary() { return empSalary; } public void setEmpDob(Date empDob) { this.empDob = empDob; } public Date getEmpDob() { return empDob; } }
Employee Static Data will basically populate the values for Employee Data Model class as shown below,
package view; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.regex.Pattern; public class EmpStaticData { List emplist = new ArrayList(); public EmpStaticData() { String dobStr1="09/25/1973"; String dobStr2="09/15/1983"; Date dobDate1 = null; Date dobDate2 = null; DateFormat formatter; formatter = new SimpleDateFormat("MM/dd/yyyy"); try { dobDate1 = (Date)formatter.parse(dobStr1); dobDate2 = (Date)formatter.parse(dobStr2); } catch (Exception e) { e.printStackTrace(); } //int empId, String empName, String empDept, int empSalary, Date empDob emplist.add (new EmpDataModel(21288, "James Smith", "Engineering", 55000, dobDate1 )); emplist.add (new EmpDataModel(21299, "Peter Parker", "Sales", 65000, dobDate2)); } public List showAllEmployees() { return emplist; } }
Once our Java classes are ready we will use
Employee static data class to generate datacontrol by as shown below
Drag and Drop the data on the page as form as well as graph |
Passing data using setPropertyListener |
Sometimes , it also becomes critical to pass data to another page , using From and To values , where From value can be from any data source and To value can be directly written into pageflow scope , usually this is handled by a button click invoking set Property Listener [xml] <af:button text=”Greet” id=”b5″ action=”3to2″> <af:setPropertyListener from=”#{bindings.empName.inputValue}” to=”#{pageFlowScope.MyBean.username}” type=”action”/> </af:button> [/xml]
Using ADF Utils and Bindings to access page variables. |
Download the source from here ..