Sunday, August 29, 2010

Press Edit Button to make Table Row Editable.

It seems very logical to have a button in a table row that will change the state of the row from read only to editable.
ADF supports this in a diferent way, The table has a property called EditingMode.

If you set the value clickToEdit, then, each time you click a record, it will become editable.

Here is  way of doing the same thing but with a button.
So instead of clicking on the row to edit, we ll have to click on the button and make the row editable.

Download the sample application.

This is what we want to have as functionality:

First we will create a transient attribute in our Entity Object
This attribute will be called editable and will have type of Boolean
We will add this attribute in the VO.

In the VO Row Impl java class, we will override the isAttributeUpdatable method.

Now, if the editable transient attribute has value true, we will return the super method, else we will return false.

Well, this means that every time we fetch data from the View Object, cached or not, this check will be done and according the value, the attribute will be updatable or not.

How to set value to this attribute:
We want this to happen when we press the button.
So, first we create another column,

add a button with partialSubmit=true,
 Inside the button we add a setPropertyListener (Recomended instead of setActionListener)

Type: action
From: #{true}
To: #{binding.editable.inputValue} <--- we have to add the binding on our pageDef

This will represent the editable value on the current record.

Last, place partialTrigger on the table from the Button

The other partialTrigger you see on the screenshot is from create insert button.
So, if you run your application you will see that when you press edit button on a row it will become editable.

Infact, you can make more than one row editable, simply by clicking the corresponding button...

But what happens when we commit??
We need to set the value back to false..
Back in the EntityObject impl java class, override The doDML method, and before super, set the attribute to false.

This will post the false attribute and after the commit it will have value false.
So all the rows will be read Only.

As far as the createInsert operation:
We could do the same on the createInsert button, as the edit button.
Just for the difference, we can do it somwhere else in the model.

In VORowImpl java class, Override the create method and set value true to the editable attribute.

Thats about it...

So now, we have a table we readOnly behavior and an edit button that enables that row.
After commit, the row(s) become readOnly again.

Download the Sample Application.



  1. Dimitri.... Excellent post.... Nice and easy

    However I do get an error message "java.lang.nullpointer" when when executing the line "if(editable.equals(true)){"

    I'm using JDev and JDK 1.6.0_31

    Any ideas where I might start looking? Do I need to default the editable value?

  2. Excellent post indeed, I am getting null pointer exception as well - any clue?

  3. I was also getting the null pointer exception but the below code solved the problem.

    public boolean isAttributeUpdateable(int i) {
    boolean trmp;
    System.out.println("inside method ------->1");
    //ArcDcIdsXrefImpl tmpobj = new ArcDcIdsXrefImpl();
    Boolean editable = this.geteditable();
    //System.out.println("inside method ------->2");

    if(editable!=null && editable.booleanValue()){
    // System.out.println("inside method ------->3");
    // System.out.println("inside method ------->4");

    return trmp;
    // System.out.println("inside method ------->5");
    return false;


  4. I get the same null pointer exception. this.Editable is picking null values and passing the same onto the variable "editable". Should i be changing something on the tables end?