05 May, 2012

ADF & OAF : Add Attribute to View Object Progmatically

You can add transient attribute to view object progmatically at run time.
You can use this transient attribute to store any temporary data for every row in view object or create generic solution in your custom framework for general purpose.

ADF
in ِADF you can use below code anywhere in ApplicationModuleImpl class
I will check existence of attribute XXAttr, If it is not exist I will add it to view object
     ViewObject vo = this.findViewObject("ViewObjectName");  
     if (vo != null) {  
       try {  
         String transientAttr = vo.findAttributeDef("XXAttr").toString();  
       } catch (Exception e) {  
         vo.addDynamicAttribute("XXAttr");  
       }  
     }  


OAF
Same like sample in ADF I will check existence of attribute XXAttr, If it is not exist I will add it to view object


    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);

        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        OAViewObject vo = (OAViewObject)am.findViewObject("ViewObjectName");

        if (vo != null) {
            try {
                String transientAttr = 
                    vo.findAttributeDef("XXAttr").toString();
            } catch (Exception e) {
                vo.addDynamicAttribute("XXAttr");
            }
        }
    }

Thanks
Mahmoud A. El-Sayed
Recommended Post Slide Out For Blogger