Sunday, November 8, 2009

Getting the Value from a SelectOneChoice List (Not Index)

One of the Issue I found when I use af:selectOneChoice component that when I want to get the selected value from one of the selectOneChoice attribute from backingbean I found the return value is the index of selected value not the value. (Using HR Schema)
assume we have an EmployeesView which has a DepartmentId (as a lookup to DepartmentView) and want to get the the value of selected Department. To solve this problem do this :

BindingContainer bindings =BindingContext.getCurrent().getCurrentBindingsEntry();
JUCtrlListBinding listBinding =(JUCtrlListBinding)bindings.get("DepartmentId");
Row selectedValue = (Row) listBinding.getSelectedValue();


- DepartmentId the selectOneChoice Attribute
which you want to get its value.
- selectedValue is the row of the lookup attribute (In this case will be the row of the selected department).

Monday, November 2, 2009

How To Make Declarative Component

Declarative Component is used to build a reusable UI component. You can design your own component using ADF Faces Component. To establish declarative component follow this Steps :
1- Make a new ADF Application.
2- In ViewController Project, right click in a web content folder -----> new.
3- In Web tier -->JSF--> JSF Declarative Component.
4- Enter Declarative component name (e.g. UserInfo) and package.
5- Define a tag library name. This tag library name will be the name of the library in which the component will be stored and is the name you will see in the drop down of the component palette when you use the component.
There is a facet Definitions - Attributes – Methods. You can define any of these
depend on your component. Assume we want to make a component for user
Information it contain a three text as name, Address and telephone and one toolbar that
can manage user to add any button to do any action. In this case we need one facet to
add in the toolbar and three attributes then press Ok.
6- Drag and Drop af:panelBox in the page and set its Text to User Information thin in panelBox toolbar facet drag af:facetRef and choose your facet.

7- Drag af:panelFormLayout and insert inside it a three inputText and set its label to Name, Address and Telephone.

8- In the af:inputText (Name) edit the value by choosing Expression Builder then from JSP Object choose attrs then Name.
9- Repeat this Steps to af:inputText (Address) and af:inputText (Telephone).
10- In ViewController Project right click then choose Project Properties.
11- Choose Deployment then press new.

12- In Archive Type choose ADF Library JAR File and Enter the name of Jar as (UserInfoJar) then press Ok.

13- In ViewController Project right click then choose Deploy -->UserInfoJar-->To ADF Library JAR.

14- In Recourse Palette -> New Connection -->File System.

15- Enter A connection name and the path of your JAR file then Press Ok.

16- To use this component at any project open the project and go to Resource Palette and right click on the UserInfoJar.jar file then choose Add To Project then press to Apply Library.

17- Now go to Component Palette you will find your UserInfo Component.

You Can Download the declarative component example from this link :

Sunday, November 1, 2009

How Can You Manipulate With Table Column Filter Fields

One of the af:table feature is a filter over its column to filter its data. You can manipulate with this fields with backingbean, this manipulation can be as :
- Execute some code before filtering.
- Execute some code after filtering.
- Add something to the value you enter to filter before filtering.
- Re-execute query.

to do this follow this steps :

1- Bind your table in the backingbean ( Binding property of table set #{myBackingbean.myTable}).
2- In table QueryListener property set its value to
#{ myBackingbean.onTableQueryExecuted}
3- In your backingbean implement onTableQueryExecuted with:
public void onTableQueryExecuted(QueryEvent queryEvent) {
// If needed, do something before the table's query is processed


// Where DeptView1Query is a searchRegion name in your binding
// If needed, do something after the table's query is processed

public static Object invokeMethod(String expr, Class[] paramTypes,
Object[] params) {
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elc = fc.getELContext();
ExpressionFactory ef = fc.getApplication().getExpressionFactory();
MethodExpression me =
ef.createMethodExpression(elc, expr, Object.class, paramTypes);
return me.invoke(elc, params);

public static Object invokeMethod(String expr, Class paramType,
Object param) {
return invokeMethod(expr, new Class[] { paramType },
new Object[] { param });

To get the value which you enter to filter the column :

private FilterableQueryDescriptor getTableQueryDescriptor() {
return (FilterableQueryDescriptor)getMyTable().getFilterModel();
private Map getTableFilterCriteria() {
return getTableQueryDescriptor().getFilterCriteria();

getTableFilterCriteria().clear(); // to clear all filds.
getTableFilterCriteria().put("Dname","%N%");// to set value of the filterable field .
getTableFilterCriteria().remove("Dname"); // to clear the Dname Filterable text only.
getTableFilterCriteria().get("Dname");// to get the value that you enter to filter the table.

To re-execute query:
QueryEvent queryEvent = new QueryEvent(getMyTable(),getTableQueryDescriptor() );

Filling SelectOneChoice From Backingbean

On of the major component in tha ADF RC component is a af:selectOneChoice. You can fill this component from backingbean by tow ways:

A) Fill SelectOneChoice Component Programmatically:
1-In the backingbean you can define a variable that hold the selected Value (the value which you are select from selectOneChoice component ) [e.g public String selectedValue;] and make its setter and getter.
2- In the backingbean you can define an array of selectItem that will fill the selectOneChoice(e.g. public SelectItem[] elements = null; ) and make its getter and setter.
3- In the getter of selectItem write this code :

where : UCustomerView1Iterator is the Iterator which its data will fill the selectOneChoice (You must add this iterator in the pageDef).

You backingbean it should be like this :

4- In you page Drage a selectOneChoice component and set its value to :
5- Insert f:selectItems inside af:selectOneChoice and set its value to:
B) The second way to fill the selectOneChioce is to use af:forEach component and I prefer this way:
1- In the pageDef make a table in the binding section that will fill your selectOneChoice(assume that you make a DeptView1 table in the binding.
2- DeptView1 Table is point to the DeptView1Iterator make its length to -1.
3- Drag and drop a selectOneChoice component and set its value to the attribute in the backingbean.
4- Insert inside selectOneChoice af:forEach component and set Items property to : #{bindings.DeptView1.rangeSet} and set Var property to row.
5- Insert Inside af:forEach af:selectItem set Value Property to #{row.Deptno} this represent the return value of the selectOneChoice if you want the return value be a name of the department set Value Property to #{row.Dname}. Set the Label Property to #{row.Dname}.(Where Deptno and Dname is the attribute of the iterator you use to fill selectOneChoice).
you can download an example from here.

Get Bindings From Backingbean

In many situation we need to get binding container from our backingbean to execute some of the operation as ( Commit - Rollback - Next - Last - ExecuteWithParam - ............. ) or get your Iterator to get some information as (get Current Row - get ViewObject - get number of row count - refresh iterator - .............. ) There are two way to get your binding container from backingbean :

1- BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
then you can use bindings object to execute some of binding operation as commit operation as:
OperationBinding operationBinding = bindings.getOperationBinding("Commit");

2- The second way to get binding container is to define a method that return binding container as :

private BindingContainer bindings;
public BindingContainer getBindings() {
if (this.bindings == null) {
FacesContext fc = FacesContext.getCurrentInstance();
this.bindings = (BindingContainer)fc.getApplication().evaluateExpressionGet(fc,"#{bindings}",
return this.bindings;

to get binding and execute a commit operation :
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;