Monday, December 19, 2011

ADF TaskFlow Method Call On page load

In taskflow we can drop execute with parama e.g. employees with dept 10 from datacontrols. You can even right click and say create page definition and define operations there for taskflow.

The binding for this will be with method now you need to change this binding and update it to backing bean method (binding value: #{backingBeanScope.MethodCall.CalledMethod}) and now you can execute the execute this mehtod from operation binding as in below code

public void CalledMethod() {

DCBindingContainer dc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = dc.getOperationBinding("ExecuteWithParams");
operationBinding.execute();
}

In this way you intitialize your page.

Thursday, December 15, 2011

Passing values between ADF Task Flow

1) IF we have one taskflow inside another taskflow. The PageflowScope can be use to set values into variables i.e.
AdfFacesContext.getCurrentInstance().getPageFlowScope().put("varName","varValue");
and select the child taskflow(this task flow should have relevant parameters defined) and in properties give value to parameter value as #{pageFlowScope.varName}
2) When we have Jsff (region) within which we have taskflow pulled and we need to pass value to this taskflow then go to pagedefinition for the page/region and select this taskflow from executables and in properties you provide value to particular variable like #{pageFlowScope.varName}

Sunday, December 4, 2011

Check Authentication & Get Logged in user id

Use this code in you application module Impl class in methods

1) SecurityContext securityContext = ADFContext.getCurrent().getSecurityContext();
// 2. authentication check
if(securityContext.isAuthenticated()){
String username = securityContext.getUserName();

2) String userName = ADFContext.getCurrent().getSecurityContext().getUserName();
if(ADFContext.getCurrent().getSecurityContext().isAuthenticated()){

Remove all rows from viewobject.

Define a method in Application Module Impl class.
Using below sample code you can delete all the rows in current resultset of view object
In Application Impl all the methods will have viewobject accessors(get and set viewobjects)

ViewObjectImpl employeesVO= getEmployees();
// 1. reset iterator to start before first row
shoppingCartVO.setRangeSize(-1);
Row[] rows = employeesVO.getAllRowsInRange();
// 2. iterate over rows and remove each instance
for(Row row: rows){
row.remove();
}
getDBTransaction().commit();

Saturday, December 3, 2011

Table Column Sum / Table Footer Displaying Sum of Column

Lets say we have employees table and we want sum on salary column.

Drag viewobject and create table normally.
Select Salary table -> Right Click -> Facet Column -> Footer
From structure pane for this column add output text filed and surround it with panel grouplayout (layout property as horizontal and halign as right)

You can have two view object viz one for just employees and secont view object to contain the sum query.

The output text should refer to the sum value of the second view.
Checout the attached application

https://docs.google.com/open?id=0B-zSRgGSIJgNMTIyMTk1Y2ItMDNjMS00N2Y5LWFkYWItNWI4YWY4YzUyZWQ2

Monday, November 28, 2011

SelectOneChoice ValueChangeListener ProcessUpdates

When value is changed in selectonechoice and you have valuechangelistener associated with it, which has iterator and a variable which captures particular attribute but the problem is in valuechangelistener if you dont specify below line of code you will see that the values are not right (some old selection is captured) hence give this code in valuechangelistener.

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
e.g of complete method
public void PersonSelected(ValueChangeEvent valueChangeEvent) {

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
BindingContext bctx = BindingContext.getCurrent();
DCBindingContainer bindings = (DCBindingContainer)bctx.getCurrentBindingsEntry();
OperationBinding opr = (OperationBinding)bindings.getOperationBinding("AllFruitsEP");
Object result = opr.execute();
DCIteratorBinding allFruitsItr = bindings.findIteratorBinding("AllFruits1Iterator");
AttributeBinding personId = (AttributeBinding)bindings.getControlBinding("Personid");
System.out.println("Person ID:"+personId);
System.out.println("Iter size:"+ allFruitsItr.getViewObject().getRowCount());
if (!opr.getErrors().isEmpty()) {
System.out.println("ERROR");
}
}

Saturday, November 26, 2011

Requied Field, Show Required Message Details, Programmatically Navigate

Requirment- Navigation from one page to another only if all the fields have value/ mandatory fields are not blank
1) Page1 say we have text field and a button
2) In adfc-config pull two pages page1 & page2 and controlFlow "gotoPage2" from page 1.
3) set action property for button on page1 to "gotoPage2"
4) Now for textfield on page one set below properties
Behaviour- Required-> True
Appearence- Required Message Details value -> {0} is mandatory, cannot be blank (sample message)
And simply run the page.
This will even work when you have some code attached to submit button and you want to return/navigate to specific control flow. This is what you need
Create a java class with request scope in adfc-config and to your button add expression to a method, and the method body can be like
public String SubmitBtn() {
return "gotoTest"; //this is the value on adfc-config control flow
}


Download Application

ADF Error Handler Page

In your ADF Task Flow-> Overview->General Tab - Exception Handler define a simple jspx page call it as Error.jspx (If you dont have this page then first create it and then assiociate it as exception handler)

Friday, November 25, 2011

ADF Passing Parameter to Page - Execute with parameters

Requirement: Two page with different tables/viewobject one click on any record on first page next page should display values based on that parameter (execute with parameter)
1 - First Page to have list of records in table etc convert first column output text field to command link (link) item. If you see a warning on this field then in structure page remove and ConvertToNumber or other attribute which is not required with the field. This is coming from View1 object
2 - View2 is having query with bind variable say :parm1, now we need to pass value from view1 into parm1 of view2 object on click of that link.
3- Second page Drag and drop view2
4- In taskflow definition drag and drop the two pages. Now in DataControls expand View2 definition and in operations select ExecuteWithParameter and drag and drop it between the two pages in taskflow definition. It will ask for parameter value, In value dropdown select Expression ->ADF Managed Beans->pageFlowScope and type a parameter name like pid after #{pageFlowScope}i.e.#{pageFlowScope.pid}
5- Expand navigation control from from ExecuteWithParam operation to Page2 and from page1 to ExecuteWithOperation say the control link to be "select"
6-On first page select the link and action  attribute value select "select" from dropdown.
7-Now we need to pass value of this record to executewithparam opration. From operation panel select setPropertyListener and drop it on command link and set the values as From: #{row.DepartmentId} To:#{pageFlowScope.pid} Type: action

Sunday, November 13, 2011

Table SelectionListener

Drag and drop table with rowselection checkbox selected and assign selection listener property to binding bean method

public void TableSelect(org.apache.myfaces.trinidad.event.SelectionEvent selectionEvent) {


RichTable richTable = (RichTable)selectionEvent.getSource();

CollectionModel tableModel = (CollectionModel)richTable.getValue();

JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding)tableModel.getWrappedData();

Object selectedRowData = richTable.getSelectedRowData();

JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding)selectedRowData;

for (Object o : nodeBinding.getAttributeValues()) {

System.out.println("Selected values " + o);

}

Thursday, November 3, 2011

Accessing Attribute Programmatically

When you have defined attributes on pagedefinition and you want to access it in backing bean use below code to do this:

DCBindingContainer dbc = (DCBindingContainer)this.getBindings();
AttributeBinding attr =((AttributeBinding)dbc.getControlBinding("FirstName"));

AttributeBinding email = ((AttributeBinding)dbc.getControlBinding("Email"));

System.out.println("First Name:"+attr+" "+email);

Saturday, October 22, 2011

Programmatically Accessing Application Module, ViewImpl & ViewRowImpl classes

//the syntax of configuration is 1st parameter to have full path and second to have modulename with Local added to it


public static void main(String[] args) {
ApplicationModule appModule =
Configuration.createRootApplicationModule("com.adf.sample.model.SampleModule", "SampleModuleLocal");
DepartmentsViewImpl deptVo = (DepartmentsViewImpl)appModule.findViewObject("DepartmentsView1");
while(deptVo.hasNext()){
DepartmentsViewRowImpl deptRowVo = (DepartmentsViewRowImpl)deptVo.next();
System.out.println("Department Name: "+deptRowVo.getDepartmentName());
RowIterator empVo = deptRowVo.getEmployeesView();
while(empVo.hasNext()){
Row empRow = empVo.next();
//EmpDetailsViewViewRowImpl empRow = (EmpDetailsViewViewRowImpl)empVo.next();
//System.out.println(" "+empRow.getFirstName());
System.out.println(" "+empRow.getAttribute(1));
}

}

}

Wednesday, October 12, 2011

ADF Insert Row and Use it in procedures or funtions without commiting this.getDBTransaction().postChanges();

Given senarios like we need to create a row in a particular table and then call a procedure which uses the key from this row and inserts records in another tables all without commiting this to database. This is done using this.getDBTransaction().postChanges();

You can define this is any impl classes of view object and expose it to client. If you make any changes to view object in backing bean then call this method before invoking any procedures :)

Application Module Impl.java Method Declaration

You should define your custom methods in ApplModuleImpl.java class for reusability.

Sample Method :
public void getEmpDetails(Number empId) {
ViewObjectImpl myViewQuery = this.getMyViewQueryVO1(); //the view you have defined and added to appmodule.xml file
myViewQuery .setNamedWhereClauseParam("empId", empID); //view with param
myViewQuery .executeQuery();

//to commit you can use
getDBTransaction.commit() / rollback()

}
After defining this method you need to add this method to AppModule.xml file to expose it to client and you will find it in DataController panel.

To invoke this metod: In your jsff or jspx page definition in bindings create method binding for this method. you can also define values for this here or programmatically do it as

bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("getEmpDetails");
operationBinding.getParamsMap().put("empId", employeeId);
operationBinding.execute();


public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}

Monday, October 10, 2011

ADF Table automatically loads in between data entry?

Set the content delivery property to lazy to solve this issue.

Tuesday, October 4, 2011

Helpful ADF Blogs

ADF Demo Links:
http://jdevadf.oracle.com/adf-richclient-demo/faces/components/lov/comboLOVWithCustomActions.jspx;jsessionid=xsmhTJpVKCyyQvnRrF2pnQgKyx2XbSZbnncNdNy3mlMQJqsGvlqS!446378343?_afrLoop=392807939445182&_afrWindowMode=2&Adf-Window-Id=w0


http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html

Thursday, September 29, 2011

Navigation based on popup outcome

To navigate to some other page you should not use dialoglistener because it will not navigate from your method instead you should define buttons in your popup and the action of these buttons to return to some page e.g.

public String gotoHomePage(){
return "gotoHome"
}

This will not work with dialoglistener buttons but will work and navigate to home page if custom buttons are used. :)

Thursday, September 15, 2011

Custom Methods in Application Module & ViewObject

We can define method inside Application Moduel Impl class for funtionality which is using multiple viewobjects and ViewObject Impl class is used for functionality specific to a particular Viewobject.

ViewObject Impl and RowImpl:
- We have two java clases for each view object
- Impl java class can contain method to either delete a row from this view object e.g.



public void deleteEmployee() {
Row currentRow = this.getCurrentRow();
if (currentRow != null) {
currentRow.remove();
this.getDBTransaction().commit();
}
}

Now you need to expose this method to client interfcae (This is present in Viewobject-> Java->ClientInterface\


- Now in your jspx/jsf page definition insert bindings methodAction, select Employees Viewobject and this mehthod will be available in operations.


- Now to invoke this method you can either call it on mehtod click in ActionListener give this value #{bindings.deleteEmployee.execute}

Wednesday, September 14, 2011

Detailed Table Edit Selected Row (Click to Edit) Attribute

Assume that we have a detailed employee table and when we select a particular row I want that row to become editable.

For this to happen select adf table i.e. af:table t1 and in property listener in Behaviour tab set EditMode property value to "clickToEdit" and thats it. (Note the adf table should not be read only)

Attribute level Custom Message Display

E.g. When creating new employee if the user forgets to provide mandatory field e.g. firstname then you can specify the required message details field in property inspector as follows

{0} is Mandatory.Please provide value

The value in {} should be 0 to reflect to current fields.

Message will be displayed like "FirstName is Mandatory. Please provide value"

Tuesday, September 6, 2011

SelectOneChoice Selected value in attribute without loop

1) Go to page definition
2) Create Employees Iterator from employees view object.
3) In bindings create a list for employees first name list as in screen shot (does not update base datasource).

4)On jsf page drag selectone choice from components section and in popup give binding for the list that you created in step 3 also set autosubmit property to true for this dropdown.

5) Now in page definition create a

6) Create one output textfield in jsf page and give its value as #{bindings.FirstName.inputValue} and set partial trigger property to the dropdown id
n attributebinding with the same iterator.

Monday, September 5, 2011

Attribute Binding

Attribute Binding is of greate help, It can be used to get the values of current selected row in table, selectonechoice etc instead of iterating through the viewobject iterator.

1) On you jsf/jsff page right click and say goto page definition.
2) In bindings click to add (+) and select attributevalues
3) Select datasource and in second dropdown select the attribute you want this variable to store e.g. emp id, name etc
4) Now which ever row/record you select dynamically this attribute will hold the value of that record e.g. for employee if you select some middle row this will show the emp id of that record.
5) The value of this variable is accessed using following expression:
#{bindings.FirstName.inputValue} (based upon the attribute you have specified) or programmatically

DCBindingContainer dbc = (DCBindingContainer)this.getBindings();

AttributeBinding attr =((AttributeBinding)dbc.getControlBinding("FirstName"));

Your can even specific this as input parameter to you execute with parameter operations.

ADF Dialog confirmation

Dialog Tutorial Link:
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/77-ok-cancel-support-in-dialog-351871.pdf

Monday, August 22, 2011

SelectOneChoice selected value stored in variable

1) In view object define a drop down list for department name (it should display a list of departments).
2) Drag and drop a table attribute(column eg Department name column alone) on a jsff page.
3) Right click on jsff page and select goto page definition. (use this rather than bindings tab)
4) In page definition.xm file goto source tab and find variablesIterator tag. If this tag is not present in design tab in executables region add variablesIterator by click the + sign and creating variable iterator object.
5) In source tab under variableIterator table define a variable name as under:
(lessthansign)variable name="personId" type="oracle.jbo.domain.Number" (greatthansign)
6) Now goto jsff page of page definition inside bindings create one attributeValues binding by clicking + sign. Specify the Datasource as variables and select Attribute name as varDeptId as declared earlier.
7) Now goto page bindings and double click the LOV of department name that you have created in step 2. Select base data source type as variables.
In list datasource select departments view. In data value select the variable and in list attribute select the attribute you want from department column e.g department id and select the display element i.e. the value you want to display on screen.
8) This binding varaible we contain the value you have selected in dropdown list. Your can use JSFUtils to resolve the expression value or assign this value to and execute with paramters operation. The expression for this values is #{bindings.varDeptId1.inputValue}

Wednesday, May 18, 2011

ANT DEPLOYMENT

http://www.oracle.com/technetwork/articles/adf/part4-098813.html

Friday, April 29, 2011

Usefull ADF Blog

http://adf-blogs.blogspot.com/

Sunday, April 10, 2011

ADF Taskflow Return to parent after completing taskflow

Use "Parent Action" component to call control flow of parent
Also in your parent taskflow you should have a control flow for this outcome.
The child will be calling this taskflow using parent action activity.

Thursday, April 7, 2011

ADF TaskFlow Parameters

You will require to pass page flow scope parameters from your current environment into the adf taskflow:

Open the taskflow in overview mode and create a parameter

Open the jspx page or the fragment where you are plcing this taksflow,
go to bindings tab and give the input value for taskflow parameter from you page flow variable as in below image

Thursday, March 31, 2011

PanelCollection set width 100 percent

Select Panel collection in properties set Style Class property to "AFStretchWidth"

Thursday, March 24, 2011

JNDI Connection in jdeveloper

In applicationmodule properties set the database connection to jdbc datasource and the value "jdbc/your_datasource_name"

Wednesday, March 9, 2011

Application Context

In viewcontroller project properties -> Java EE Application. give application name and context name here.

Thursday, March 3, 2011

ADF 11g: Deleting all rows from Viewobject programmatically.

On button event write below code:

DCBindingContainer dc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

ViewObject myVo= dc.findIteratorBinding("myVoIterator").getViewObject();
RowSetIterator rsI = myVo.createRowSetIterator(null);
while(rsI.hasNext()){
rsI.next().remove();
}
rsI.closeRowSetIterator();

Sunday, February 27, 2011

PageFlowScope variables

Drag and drop Set Property lister from operations pallette onto any component on your page. This gives flexibility to assign values to variables on the go whithout declaring them anywhere.

The value "test" will be assigned to variable demo, note the demo variable is not declated anywhere.

This can be used in many places e.g in menuitems create command menu items and you can drag and drop property listener on each of them. On clicking any of the items you assign different values to just one variable everywhere say #{pageFlowScope.menuClicked} and values as user defined.

Now in bounded taskflow say adfc-config.xml you can define controlflow for each of these values

You can also programmatically access pageFlowScope variables:
AdfFacesContext.getCurrentInstance().getPageFlowScope().put("user_var","value" );
System.out.println("value"+AdfFacesContext.getCurrentInstance().getPageFlowScope().get("user_var")); //user defined variables as first argument.

This can be used in lot of places e.g. if you three tabs add, update, delete you can use single interface with all the buttons setting the buttons rendered property to values of this variable like this:

#{pageFlowScope.selectedTab == 'addTab'}

Monday, February 21, 2011

Oracle ADF View Criteria

We can have one view object to have multiple view criterias which can be used to execute at run time. Define the view criteria at desin time and use following code to execute any of the view criteria:
DCBindingContainer dc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
ViewObject vo=dc.findIteratorBinding("SubmissionViewRptPrdVO1Iterator").getViewObject();
System.out.println("View name: "+vo.getName());
ViewCriteriaManager vcm = vo.getViewCriteriaManager();
ViewCriteria vc=vcm.getViewCriteria("RptPrdForUser");
VariableValueManager vm=vo.ensureVariableManager();
vm.setVariableValue("userId", "3");
vo.applyViewCriteria(vc);
vo.executeQuery();

Monday, February 14, 2011

Database(Tables Objects) with data export steps.

Select all tables you need to export -> right click -> upload
this will create the sql script file. Which you can execute on your local database.

Friday, February 4, 2011

ADF Timestamp & Date

In view object attribute value specify type as expression and give value as

adf.currentDate
adf.currentDateTime

Wednesday, February 2, 2011

ADF Sequence number

Create java classes for entity object and for the attribute setter method put below code and your sequence name instead of seq1.

SequenceImpl s = new SequenceImpl("seq1",getDBTransaction());
setAttributeInternal(SUBMHEADID, s.getSequenceNumber());

Note: you need to provide some dummy value like -1 in the display to avoid madatory validation. At the time of insert it will take value from sequence.

Wednesday, January 19, 2011

ADF: Code to insert record in database table programmatically

Code for inserting record in Database programmatically.

public String cb2_action() {
// Add event code here...
Row newRow;
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
Object result ;
ApplicationModule am = ADFUtils.getApplicationModuleForDataControl("BHCModuleDataControl"); //application name from data controls and not application module
ViewObject myView = am.findViewObject("TempView1"); //view name from data controls
newRow = (oracle.jbo.server.ViewRowImpl)myView.createRow();
newRow.setAttribute("Name", "Amol");
myView.insertRow(newRow);
operationBinding = bindings.getOperationBinding("Commit");
result = operationBinding.execute();

return null;
}
Note: Drag and Drop Commit operation from Datacontrol on jsf page to get Commit binding in page definition.

Thursday, January 6, 2011

Navigating between JSF pages programmatically

FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
NavigationHandler navHandler = application.getNavigationHandler();
navHandler.handleNavigation(fctx,null, "name of navigation case");