Friday, April 22, 2016

How to use same OAF page for update and view mode

In this blog we will discuss, how to use same OAF page for update the record and view the record. (in view mode all the fields will be read only and save and canel button will be hidden).

I am taking example of advanced table.

In adavanced table, we have two columns one for update and another for detail.

 When user click on update icon, page should open in update mode (all fields will be updateable and user will be able to save the changes).
When user click on detail icon, page should open in view mode (all fields will be read only and OraDataText CSS should be applied on the page). Save and canel button will be hidden and return navigator link will be visible to navigate back to the previous page.

First of all we will pass one parameter say pageMode to next page through both the column using parameter property of bean item OR you can pass pageMode parameter using hashMap in event handling method.

params.put("pageMode", "Update");

                pageContext.setForwardURL("OA.jsp?page=/xx/oracle/apps/xxapp/webui/recordPG",
                                          null,
                                          OAWebBeanConstants.KEEP_MENU_CONTEXT,
                                          null, params, true,
                                          OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
                                          OAWebBeanConstants.IGNORE_MESSAGES);

Now in recordPG we will check this parameter and decide what to do

// for update page
String pageMode = pageContext.getParameter("pageMode");
if ("Update".equals(pageMode))
{
                OAWebBean returnNavigation =
                webBean.findChildRecursive("ReturnNavigation");
            if (returnNavigation != null) {
                returnNavigation.setRendered(false);
            }
}

// for detail page
if ("Detail".equals(pageMode))
{
  // now we will set read only property for entire page and set CSS style
// first of all hide page button bar
            OAWebBean pageBtnBar = webBean.findChildRecursive("PageBtnBarRn");
            if (pageBtnBar != null) {
                pageBtnBar.setRendered(false);
            }

makePageReadOnly(pageContext,
                                          webBean,
                                          excludeBean, // HashMap -- provide bean name which do not want to make read only
                                          "OraDataText");  

}


    public static void makePageReadOnly(OAPageContext pageContext,
                                          UINode childNode,
                                          HashMap excludeBean,
                                          String cssClass) {
        if (!excludeBean.containsValue(childNode)) {

            if (childNode instanceof OAMessageStyledTextBean) {
                ((OAMessageStyledTextBean)childNode).setCSSClass(cssClass);
 ((OAMessageStyledTextBean)childNode).setReadOnly(true);
            } else if (childNode instanceof OAMessageTextInputBean) {
                ((OAMessageTextInputBean)childNode).setCSSClass(cssClass);
 ((OAMessageTextInputBean)childNode).setReadOnly(true);
            } else if (childNode instanceof OAMessageLovInputBean) {
                ((OAMessageLovInputBean)childNode).setCSSClass(cssClass);
 ((OAMessageLovInputBean)childNode).setReadOnly(true);
            } else if (childNode instanceof OAMessageDateFieldBean) {
                ((OAMessageDateFieldBean)childNode).setCSSClass(cssClass);
 ((OAMessageDateFieldBean)childNode).setReadOnly(true);
            } else if (childNode instanceof OAMessageChoiceBean) {
                ((OAMessageChoiceBean)childNode).setCSSClass(cssClass);
 ((OAMessageChoiceBean)childNode).setReadOnly(true);
               
            } else if (childNode instanceof OAMessageCheckBoxBean) {
                ((OAMessageCheckBoxBean)childNode).setCSSClass(cssClass);
 ((OAMessageCheckBoxBean)childNode).setReadOnly(true);
            }
            int indexedChildCount =
                childNode.getIndexedChildCount(pageContext.getRenderingContext());
            for (int recursiveChildCounter = 0;
                 recursiveChildCounter < indexedChildCount;
                 recursiveChildCounter++) {
                if (!excludeBean.containsValue(childNode.getIndexedChild(pageContext.getRenderingContext(),
                                                                         recursiveChildCounter))) {
                    setCSSOnChildBeans(pageContext,
                                       childNode.getIndexedChild(pageContext.getRenderingContext(),
                                                                 recursiveChildCounter),
                                       excludeBean, cssClass);
                }

            }
        }
    }

Thats all folks for making same page updatable and read only. Hope it will help you....

Wednesday, April 13, 2016

Dynamically set document category for attachments

Some time we get requirement that based on some conditions, document category should be changed.

In my case, I was working on task page, so if I open task1 then task1 document category should be displayed and if I open task2 then task2 document category will be displayed.

Below are the steps to achieve this requirment.

1. Create all required document category in oracle apps.
2. Create attachment in your page, assign entity map and create primary key. But do not create category map at design time. We will create it in our controller.


3. Now in your controller take control of your attachment bean.

accessing bean in controller
OAMessageInlineAttachmentBean taskDtlsAttachments =

(OAMessageInlineAttachmentBean)webBean.findChildRecursive("TaskDtlsAttachments");

accessing entity map of attachment
String taskDtlsAttachEntityId = taskDtlsAttachments.getEntityId();

if some how entity map is null assign entity mapif (taskDtlsAttachEntityId == null)
{
     taskDtlsAttachEntityId = "XXPRO_ENTITY_MAP";
}

if you do not want misc document category, use this code
taskDtlsAttachments.setDefaultMiscCategoryEnabled(false);     use setCategoryMap method to set document category at run time. In this method we pass entity map, array of document category and pageContext.     if (task==task1)      taskDtlsAttachments.setCategoryMap(taskDtlsAttachEntityId,
            new String[] { TASK1_document_category }, pageContext);
else if (task==task2)
       taskDtlsAttachments.setCategoryMap(taskDtlsAttachEntityId,

          new String[] { TASK2_document_category },  pageContext);