Saturday, April 15, 2017

OAF attachment to be updated / deleted by creator only

Have you ever got a requirement in EBS FND attachments where in multiple users can add an attachment of the same category but only the person who has created it can delete or update it.

I achieved it recently in OAF by creating a custom DataBoundValueVIewObject class and associating it with update and delete icons of the attachment table. Since attachment table is a seeded region, I had to extend its controller to associate custom DataBoundValueVIewObject with update and delete icons.


  1. Create a custom DataBoundValueViewObject (xxOADataBoundValueViewObject ) class:




     package oracle.apps.xx.webui;

    import java.util.Enumeration;

    import oracle.apps.fnd.framework.webui.OADataBoundValueViewObject;

    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.OARenderingContext;
    import oracle.apps.fnd.framework.webui.OAWebBeanUtils;
    import oracle.apps.fnd.framework.webui.beans.OAImageBean;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;

    import oracle.apps.fnd.framework.webui.beans.message.OAMessageCheckBoxBean;
    import oracle.apps.fnd.framework.webui.beans.table.OAColumnBean;

    import oracle.cabo.style.CSSStyle;
    import oracle.cabo.ui.RenderingContext;
    import oracle.cabo.ui.UINode;


    public class xxOADataBoundValueViewObject extends OADataBoundValueViewObject {
        public String loggedInUser;
        public String property;
        public xxOADataBoundValueViewObject(OAWebBean p1, String p2, String p3, String p4) {
            super(p1, p2);
           loggedInUser = p3;
            property = p4;
           
        }
       
        public Object getValue(RenderingContext renderingContext) {
            String value = (String)super.getValue(renderingContext);
           
            if(loggedInUser != null && value != null && !loggedInUser.equals(value))
            {
                if("disabled".equals(property))
                    return true;
                if("source".equals(property) && "UpdateSwitcher".equals(mOAWebBean.getID()))
                    return "/OA_MEDIA/updateicon_disabled.gif";
                else if("source".equals(property) && "DeleteSwitcher".equals(mOAWebBean.getID()))
                    return "/OA_MEDIA/deleteicon_disabled.gif";
            }
            if("source".equals(property)  && "UpdateSwitcher".equals(mOAWebBean.getID())) {
                    return "/OA_MEDIA/updateicon_enabled.gif";
            }
            else if("source".equals(property)  && "DeleteSwitcher".equals(mOAWebBean.getID())) {
                return "/OA_MEDIA/deleteicon_enabled.gif";
            }
            return false;
        }
       
    }                                                                                                                                                                                                     
  2. Extend AkAttachmentTableCO (standard controller for Attachment Table)                                                                                                                                                                Create a new class say xxhrAkAttachmentTableCO. Personalize OAAttachmentTablePG and  mention xxhrAkAttachmentTableCO as the controller.


    package oracle.apps.xx.ak.webui;

    import java.util.Enumeration;

    import oracle.apps.fnd.framework.webui.OABoundValueELEvaluator;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
    import oracle.apps.fnd.framework.webui.beans.OAImageBean;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

    import oracle.apps.xx.webui.xxhrOADataBoundValueViewObject;

    import oracle.cabo.ui.UIConstants;

    public class xxhrAkAttachmentTableCO extends oracle.apps.ak.attach.webui.AkAttachmentTableCO {
        public xxhrAkAttachmentTableCO() {
        }

        public void processRequest(OAPageContext oapagecontext,
                                   OAWebBean oawebbean) {
            super.processRequest(oapagecontext, oawebbean);
           
            String entityName = (String)oapagecontext.getTransactionValue("EntityName");
            if("XX_ATTACHMENT".equals(entityName)) {
                OAImageBean updateSwitcher = (OAImageBean)oawebbean.findChildRecursive("UpdateSwitcher");
                xxOADataBoundValueViewObject  boundValue = new xxOADataBoundValueViewObject(updateSwitcher, "LastUpdatedByName", oapagecontext.getUserName(), "disabled");
                xxOADataBoundValueViewObject  boundValue2 = new xxOADataBoundValueViewObject(updateSwitcher, "LastUpdatedByName", oapagecontext.getUserName(), "source");
                updateSwitcher.setAttributeValue(OAWebBeanConstants.DISABLED_ATTR, boundValue);
                updateSwitcher.setAttributeValue(OAWebBeanConstants.SOURCE_ATTR, boundValue2);
               
                OAImageBean deleteSwitcher = (OAImageBean)oawebbean.findChildRecursive("DeleteSwitcher");
                xxOADataBoundValueViewObject  boundValue3 = new xxOADataBoundValueViewObject(deleteSwitcher, "LastUpdatedByName", oapagecontext.getUserName(), "disabled");
                xxOADataBoundValueViewObject  boundValue4 = new xxOADataBoundValueViewObject(deleteSwitcher, "LastUpdatedByName", oapagecontext.getUserName(), "source");
                deleteSwitcher.setAttributeValue(OAWebBeanConstants.DISABLED_ATTR, boundValue3);
                deleteSwitcher.setAttributeValue(OAWebBeanConstants.SOURCE_ATTR, boundValue4);
            }
        }

        public void processFormRequest(OAPageContext oapagecontext,
                                       OAWebBean oawebbean) {
            super.processFormRequest(oapagecontext, oawebbean);

        }
    }                                                                                                                                                                                                            
  3. In processRequest of your main page controller add the below:
oapagecontext.putTransactionValue("EntityName","XX_ATTACHMENT");



No comments:

Post a Comment