Iterate through rows in a view Object
DepartmentsView and EmployeesView are joined by view link.
Pseudo code:
For a department row -> Get associated employee rows -> Do action for the employee rows
1. Generate DepartmentsViewRowImpl.java and EmployeesViewRowImpl.java
2. Add following custom method to DepartmentsViewRowImpl.java
public void applyEmpRise(Number rise){
RowSet emp=(RowSet)getEmployeesView();
while(emp.hasNext()){
EmployeeViewRowImpl currentRow=(EmployeeViewRowImpl)emp.next();
currentRow.setSalary(currentRow.getSalary().add(rise));
}
}
3. Expose method applyEmpRise as Client Interface and make it public
4. Drag applyEmpRise from DataControl to toolbar as ADF Parameter Form.
Accessing ADF Binding Layer from Java(Managed Bean)
Bindings are represented as Metadata during design time, and at runtime they are represented as Java Objects.
Create a page submit button to create a NEW employee & query employees of that department in the detail section.
1. Drag and drop CreateInsert operations to the form.
2. Create a SUBMIT button.
2. Drag and drop Commit operation from DataControl to the button Submit button.
3. Go to Page Bindings tab. Add action binding, Select all employees view with operation ExecuteWithParams.(deptId is parameter)
4. Create a bean binding 'employeeTable' to the Employees table.
5. Create a bean binding to Submit button.
EmployeesBean as Bean Name and onCommit method (check option Generate ADF Binding Code)
public String onCommit{
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("Commit");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AttributeBinding departementId = (DepartementId) bindings.get("DepartmentId);
OperationBinding operationBinding2=bindings.getOpeationBinding("ExecuteWithParams");
operationBinding2.getParamMap().put("deptIdVar",departmentId.getInputValue);
Object result = operationBinding2.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AdfFacesContext context=FacesContext.getCurrentInstance();
context.addPartialTarget(employeeTable);
return null;
}
}
Handling the OK and CANCEL buttons in af:dialog
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("CreateInsert");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AttributeBinding departementId = (DepartementId) bindings.get("DepartmentId);
}
DialogEvent.Outcome outcome=dialogEvent.getOutcome();
if (outcome == DialogEvent.Outcome.ok){
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("Commit");
Object result = operationBinding.execute();
}
public void onDialogCancel(ClientEvent clientEvent){
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
RichPopup popup = this.getPopup();
popup.hide();
DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("AllDepartmentsIterator");
dciter.removeCurrentRow();
ADFContext adfCtx = ADFContext.getCurrent();
String oldCurrentRowKey = (String) adfCtx.getViewScope().get(OLD_CURR_KEY_VIEWSCOPE_ATTR);
dciter.setCurrentRowWithKey(oldCurrentRowKey);
AdfFacesContext.getCurrentInstance().addPartialTarget(this.getDepartementsTable());
ADFContext fctx = ADFContext.getCurrent();
fctx.renderResponse();
}
DepartmentsView and EmployeesView are joined by view link.
Pseudo code:
For a department row -> Get associated employee rows -> Do action for the employee rows
1. Generate DepartmentsViewRowImpl.java and EmployeesViewRowImpl.java
2. Add following custom method to DepartmentsViewRowImpl.java
public void applyEmpRise(Number rise){
RowSet emp=(RowSet)getEmployeesView();
while(emp.hasNext()){
EmployeeViewRowImpl currentRow=(EmployeeViewRowImpl)emp.next();
currentRow.setSalary(currentRow.getSalary().add(rise));
}
}
3. Expose method applyEmpRise as Client Interface and make it public
4. Drag applyEmpRise from DataControl to toolbar as ADF Parameter Form.
Accessing ADF Binding Layer from Java(Managed Bean)
Bindings are represented as Metadata during design time, and at runtime they are represented as Java Objects.
Create a page submit button to create a NEW employee & query employees of that department in the detail section.
1. Drag and drop CreateInsert operations to the form.
2. Create a SUBMIT button.
2. Drag and drop Commit operation from DataControl to the button Submit button.
3. Go to Page Bindings tab. Add action binding, Select all employees view with operation ExecuteWithParams.(deptId is parameter)
4. Create a bean binding 'employeeTable' to the Employees table.
5. Create a bean binding to Submit button.
EmployeesBean as Bean Name and onCommit method (check option Generate ADF Binding Code)
public String onCommit{
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("Commit");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AttributeBinding departementId = (DepartementId) bindings.get("DepartmentId);
OperationBinding operationBinding2=bindings.getOpeationBinding("ExecuteWithParams");
operationBinding2.getParamMap().put("deptIdVar",departmentId.getInputValue);
Object result = operationBinding2.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AdfFacesContext context=FacesContext.getCurrentInstance();
context.addPartialTarget(employeeTable);
return null;
}
}
Handling the OK and CANCEL buttons in af:dialog
- ADF Dialog is child component of af:popup
- Dialog events are published to server for Ok, Yes, No
- Cancel event must be handled on client using JavaScript
- Create Dialog that commits data when "ok" is pressed
- Undo the user changes and changes on server when "cancel' button is pressed
- Create a form and drag All Departments view.
- Add create button to the page.
- Drag a Popup component to af:form
- Drop a Dialog component into Popup component
- Drop "All Department" view into Dialog component
- Create a Bean binding to Popup and table components
- Drag "CreateInsert" operation on to create button
- Create a bean binding for Create button
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("CreateInsert");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()){
return null;
}
AttributeBinding departementId = (DepartementId) bindings.get("DepartmentId);
}
- Create Action binding for commit operation in pagedef
- Drag and drop ClientListner onto Dialog component. Provide method onDialogAction & type as dialog
- Drag and drop ServerListner onto Dialog component
- Drag and drop Resource component onto Document(it should be direct child of document element)
<af:resource type="javascript">
function onDialogAction(evt){
var outcome=evt.getOutcome();
if (outcome == AdfDialogEvent.OUTCOME_CANCEL){
var eventSource = evt.getSource();
var immediate = true;
AdfCustomEvent.queue(eventSource, "DialogCancelHandlerEvent ",{},immediate);
evt.cancel();
} } - Navigate to af:dialog and create event handler(onDialogAction()) for Dialog Listner in the managed bean class. It passes object of type DialogEvent
DialogEvent.Outcome outcome=dialogEvent.getOutcome();
if (outcome == DialogEvent.Outcome.ok){
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
OperationBinding operationBinding=bindings.getOpeationBinding("Commit");
Object result = operationBinding.execute();
}
public void onDialogCancel(ClientEvent clientEvent){
BindingContainer bindings=BindingContext.getCurrent().getCurrentBindingEntry();
RichPopup popup = this.getPopup();
popup.hide();
DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("AllDepartmentsIterator");
dciter.removeCurrentRow();
ADFContext adfCtx = ADFContext.getCurrent();
String oldCurrentRowKey = (String) adfCtx.getViewScope().get(OLD_CURR_KEY_VIEWSCOPE_ATTR);
dciter.setCurrentRowWithKey(oldCurrentRowKey);
AdfFacesContext.getCurrentInstance().addPartialTarget(this.getDepartementsTable());
ADFContext fctx = ADFContext.getCurrent();
fctx.renderResponse();
}
Show Messages
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO,NULL,NULL);
fm.setDetail("Message to user");
FacesContext.getCurrentInstance().addMessage(null,fm)
No comments:
Post a Comment