Wednesday, July 20, 2011

Non-Updateable rows in ADF tables

Read-only row in an ADF table is a very common use case.Last week we had a scenario where in the user is not allowed to modify a row based on a flag.Adding to this, user should not be able to modify some of the columns which are retrieved from the database.

One way to achieve this kind of behavior is through setting the read-only property of the components in the column (like #{row.bindings.Retrieved.inputValue eq 'Y'}). If a table has multiple columns, it would be a laborious process.

To achieve the same one can override the "isAttributeUpdateable" method in the EntityImpl. Following is the code snippet:

// Comment
public boolean isAttributeUpdateable(int index) {
if("Y".equals(getSeededFlag())) return false;
//Description column is always updatable 
// if not a seeded record
if(index!=DESCRIPTION)
{
//If new record, attributes should be updatable
if(this.STATUS_NEW == this.getEntityState() || 
    this.STATUS_INITIALIZED == this.getEntityState())
            return true;
if(this.STATUS_NEW != this.getEntityState() || 
   this.STATUS_INITIALIZED != this.getEntityState())
            return false; 
        }
        
        return super.isAttributeUpdateable(index);
    }

No comments: