Pages

Wednesday, December 5, 2007

11g list of values LOV

In JDeveloper 11g TP2 ( In TP3 is the af:inputListOfValues a bit different) can you define a List of values on an attribute of a bc4j viewobject. This is very easy but you can do it also manually so you can use it with toplink or with webservices. In this blog I make an jsf page on employees where you can update the department of this employee with a list of values or a lov combobox.This is a very simple LOV but you can make it more complex by using a search area in this. I will explain this in a other blog. But how do we manually create a LOV page. First we drop employees view from the data control on the jsf page. We select an ADF Form
We use all employees attributes with include navigation controls plus include submit button.

Now go to the pagedef of this page where we create a list of values binding on the department iterator. We need this for the lov page

We don't have the department iterator so we have to select it first.
We select all the attributes of the department iterator.
Open the pagedef and rename the list of values ID to DeptnoLOV. This is how the list of values looks in the pagedef.

Now go to the page and select the last column and insert input list of values.

Now we update the af:inputListOfValues element in jspx page with this one

returnPopupListener attribute of inputListOfValues is very important, here is the method defined which copies the value of the lov to the deptno of the employee. You can also have launchPopupListener where you can limit the records of the lov.


package nl.ordina.beans;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.event.ReturnPopupEvent;
import oracle.binding.BindingContainer;
import oracle.jbo.Row;

public class LovDepartment {


public void DeptLOVReturnListener(ReturnPopupEvent returnPopupEvent) {
// Add event code here...
DCIteratorBinding EmpViewIterator = (DCIteratorBinding) getBindings().get("EmpView1Iterator");
Row rw = EmpViewIterator.getViewObject().getCurrentRow();
rw.setAttribute("Deptno",getDeptLovID());

}

private BindingContainer getBindings() {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
return (BindingContainer) valueExp.getValue(elContext);
}

private String getDeptLovID() {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings.DeptnoLOV.inputValue}", Object.class);
return valueExp.getValue(elContext).toString();
}
}

We only have to register this bean in the adfc-config.xml

Now we can delete in the jsf page the deptno column of the employee form because we have now the lov. If you don't like the LOV or inputListOfValues you can also use a combobox or inputComboboxListOfValues. You only have to use this code in the page and replace the inputListOfValues element.

Here you have the example project

7 comments:

  1. Hi,
    Can you tell us please how can we pdate an LOV after doing an add or delete into the binded table

    Thanks

    ReplyDelete
  2. Mourado please can you explain what your problem is.

    thanks

    ReplyDelete
  3. Hi,
    I am asking when we have a LOV and we
    add or delete some data from the table Like Employee how the LOV is updated

    ReplyDelete
  4. If you use the bc4j lov you can update the lov with the advanced properties
    in my example you have to edit the listofvalues attribute in the pagedef

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. Can you please give some details on latest inputComboboxListOfValues?

    ReplyDelete
  7. can you please tell how to add a Create Popup for InputComboboxListOfValues? Thanks a bunch

    Jaya

    ReplyDelete