Wednesday, 24 October 2012

Forward OAF page with parameter using Hash map.


Hash map is used to store values like ‘key’ and ‘value’. This also used to call the PR when we need it .Write code for the PFR in PR when we load it. Jus check the code.

Background:
              To return a error message and also retain the selected value in a datefield Bean.



com.sun.java.util.collections.HashMap hash= new com.sun.java.util.collections.HashMap(2);

PR
{
        if ("true".equals(pageContext.getParameter("DisDate")))
        {
            OAMessageDateFieldBean dateFieldBean =(OAMessageDateFieldBean)webBean.findIndexedChildRecursive("HrEffectiveDate");
            dateFieldBean.setText(pageContext.getSessionValue("RetainEffDate").toString());
            throw new OAException("Effective date must be the first date of a pay period. Possible date "+pageContext.getSessionValue("PossibleDate").toString(),OAException.ERROR);
        }
}
PFR
{

                  
              if(pageContext.getParameter("HrContinue")!=null)
               {
                 pageContext.putSessionValue("RetainEffDate",dateFieldBean.getText(pageContext).toString());
                   pageContext.putSessionValue("PossibleDate",convertedDateString.toString());

                                       hash.put("DisDate", "true"); // setting Key value
                                     pageContext.setForwardURLToCurrentPage(hash,
                                                                             true, // retain the AM
                                                                             "Y",
                                                                             (byte)99);

                }
}

Get and set the values using Session in OAF


I faced a issue in OAF customization where the value is not getting retained when the page returns a error. Yes , when an action returns an error the code wont process further. The page wont load once again to retain the value.
                I spend lots of time in clearing this issue.  At last I manually stored the selected value in session and got it when I needed it.

I need the value to be retrieve when the button clicked. So I set the value in the Process Form Request.
I got the value in PR and set it back when the page loaded once again.


Set the value with this:

pageContext.putSessionValue("RetainEffDate",dateFieldBean.getText(pageContext).toString()); pageContext.putSessionValue("PossibleDate",convertedDateString.toString());

Give a name for the session and store the string value along with it.

Get the Session value where you need it with this :
  

dateFieldBean.setText(pageContext.getSessionValue("RetainEffDate").toString());


In this I am setting the Session value to a DateField bean. pageContext.getSessionValue("RetainEffDate").toString() will return the stored session value.

Checkbox validation in OAF using VO attribute.

I got a requirement for customization of a page where I need to create a check box. I need to do a Partial page Rendering using the Check box. That is, to enable and disable an LOV bean according to the event triggered in the check box.
I found that the Check box was already available in the seeded page and was not rendered. So I Personalized it to make it rendered.
I wrote the following code to do that Assignment.

PR
{
       
         OAMessageLovInputBean locationBean = (OAMessageLovInputBean)webBean.findIndexedChildRecursive("LocationCodeLov");
                
         OAMessageCheckBoxBean cbbean = (OAMessageCheckBoxBean)webBean.findChildRecursive("WorkAtHome");
         oracle.cabo.ui.action.FireAction FireActionA = new oracle.cabo.ui.action.FireAction();
         FireActionA.setEvent("Event");
         FireActionA.setUnvalidated(true);
         cbbean.setPrimaryClientAction(FireActionA);
        
         OAApplicationModule am = pageContext.getApplicationModule(webBean);
         OAViewObject pVO = (OAViewObject)am.findViewObject("LocationVO");
         OARow poRow = (OARow)pVO.getCurrentRow();
         String WorkAtHome = (String)poRow.getAttribute("WorkAtHome");
    
              if("Y".equals(WorkAtHome))          
              {
                  locationBean.setReadOnly(true);
              }
              else
              {
                  locationBean.setReadOnly(false);
              }
     }

PFR
    {
       
              if("Event".equals(pageContext.getParameter(EVENT_PARAM)))
                {
                   
                    pageContext.setForwardURLToCurrentPage(null,
                                                            true,
                                                            OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
                                                            OAWebBeanConstants.IGNORE_MESSAGES);
                }
     }
}
}


Note about Check box:
                When a check box is created without the checked and unchecked value, it will be defaulted with ‘on’ when checked and   ‘null’ when unchecked. But, when it stored to DB or we set the values while creating a check box will be usually stored as ‘Y’ for checked and ‘N’ for unchecked.

Tuesday, 25 September 2012

Issues faced while learning OAF


Learning OAF is not a big deal but debugging the errors while learning phase will make you feel sick and urge you dropping the plan of learning. I started learning and dropped it twice. At last I succeeded now. It took around 4 complete days to run my first oaf project.
The foremost thing to look at before learning OAF is choosing the correct version of jdeveloper. There are too many versions of jdeveloper and patches available in internet. We should make sure to select the correct version of jdeveloper.
Set the correct database connection, in this step we can test the connection in the connection create window itself. Get the correct DBC file from the DB administrator and add it in the application property.
Get the correct application name and the corresponding responsibility key which is active for set up. Below is the query to find the responsibility key and application short name and other information’s related.
    SELECT r.responsibility_name,r.responsibility_key, fa.APPLICATION_SHORT_NAME, r.version,              u.user_name, u.description, r.start_date, r.end_date
    FROM apps_fnd.fnd_user_v u,
    apps_fnd.fnd_user_resp_groups ur,
    fnd_responsibility_vl r,
    fnd_application_tl a,
    fnd_application fa
    WHERE
    ur .responsibility_id = r.responsibility_id
    AND u.user_id = ur.user_id
    AND fa.APPLICATION_ID = a.APPLICATION_ID
    AND r.application_id = a.application_id
    AND ( u.user_name = UPPER (:user_name) OR UPPER(u.description) LIKE        UPPER('%'||:user_name||'%'))
    ORDER BY 5,3,2,1

In Tools menu, select “preferences Embedded OC4J”, try to use "Default Local IP Address" option.
Lastly, take care of the naming of the package we create. The naming convention for the package we create should starts with the company name, oracle, apps and the application name. Usually the OC4J components will be stored in the package like XXX.oracle.apps.fnd.projName.Schema.Server. The User interface will be stored in the package XXX.oracle.apps.fnd.projName.Schema.webui.
These are some of the issues I faced while learning OAF. There might be lot more errors. But these are the areas where most of the mistakes happens while learning.