Tuesday, October 8, 2013

ADF: Customizing the History columns

 ADF developer will often be faced with a requirement that dictates that each some table in the database should have some audit info ( who created the record and when, who made the last changes and when).
Luckily, ADF comes with out-of-the-box support for these requirements, all you have to do is set the desired column as a history column of the desired type in the entity and the framework will take care of filling the values. There are some default types that are already defined.

Okay, so far so good. But what if you have to append something to the username or if you have to use the given name of the user(that you can get by implementing your own code to map the user name to the given name),how can you override the framework behavior?
you can acheive this by overriding the EntityImpl class with your own Class.
as for how to override the EntityImpl class check: Extending ADF Framework Base Classes.

now in your Custom EntityImpl Class, add the following code:
    protected Object getHistoryContextForAttribute(AttributeDefImpl attributeDefImpl){
        if(attributeDefImpl.getHistoryKind()==AttributeDefImpl.HISTORY_CREATE_USER){
            //add your Custom logic here
        }else{
            return super.getHistoryContextForAttribute(attributeDefImpl);
        }
    }

doing so will let you set the value of the history column with your own value.


No comments:

Post a Comment