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);