Saturday, January 11, 2014

HTTP Call Example

> HTTP call
For example we will call 'Currency Converter - Google Finance' to get conversion rate from GBP to EUR
URL: http://www.google.co.uk/finance/converter?a=1&from=GBP&to=EUR
  >Part of the source code (right click > view source)


--
declare
    l_url                  varchar2(100);   
    l_call                 utl_http.html_pieces;
    l_source_code   utl_http.html_pieces;   
    l_all_source      varchar2(32767);
    l_rate                 number;
begin
    -- The URL
    l_url := 'http://www.google.co.uk/finance/converter?a=1' ||
             '&from=' || 'GBP' || '&to=' || 'EUR';
   
    -- Make an HTTP call
    l_call  := utl_http.request_pieces(l_url);   
   
    for i in 1..l_call.count loop
        --Get all the lines from the source code returned
   
        l_source_code := utl_http.request_pieces(l_url,32767);
        l_all_source := l_all_source||l_source_code(i);       
    end loop;
   
    l_rate := substr(l_all_source,instr(l_all_source,'bld>')+4,6);

    dbms_output.put_line('Rate: '||l_rate);
   
exception
   when others then
      dbms_output.put_line('Error: '||sqlerrm);
end;

Deploying custom page

Now Deploy these custom pages and access from application

1> Move the related class files from mycalsses directory to the $JAVA_TOP in the application tier
   (Ex: C:\Jdeveloper\jdevhome\jdev\myclasses\xxhw to $JAVA_TOP)
     >> Please check if there is any existing files for any other custom page or just copy
          and paste full directory if there in only your code is there in the custom
          xxhw directory
     >> You can use any FTP tool (Ex: Filezilla)

2> Import your newly created page definition to the MDS repository
Run this script from your command prompt
Main Page
C:\Jdeveloper\jdevbin\oaext\bin\import C:\Jdeveloper\jdevhome\jdev\myprojects\xxhw\oracle\apps\per\nic\webui\xxhwHrNicPG.xml -rootdir C:\Jdeveloper\jdevhome\jdev\myprojects -username apps -password <password> -dbconnection "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = akdevdb.ak.ac.uk)(PORT = 1521)))(CONNECT_DATA = (SERVER = DEDICATED) (SID = AKDEV)))"
Update Page
C:\Jdeveloper\jdevbin\oaext\bin\import C:\Jdeveloper\jdevhome\jdev\myprojects\xxhw\oracle\apps\per\nic\webui\xxhwHrNicUpdPG.xml -rootdir C:\Jdeveloper\jdevhome\jdev\myprojects -username apps -password <password> -dbconnection "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = akdevdb.ak.ac.uk)(PORT = 1521)))(CONNECT_DATA = (SERVER = DEDICATED) (SID = AKDEV)))"

3> You can see the deployed page structure by running below script
DECLARE
--
BEGIN
    jdr_utils.printDocument('/xxhw/oracle/apps/per/nic/webui/xxhwhrnicPG',1000);
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;

4> Now Registration of Page
     >> System Administrator > Application > Function > Description



5> Properties Tab > SSWA jsp function
     > Web HTML Tab
        HTML Call : OA.jsp?page=/xxhw/oracle/apps/per/nic/webui/xxhwHrNicPG
        – Without Extension


6> Now attach this function with a menu and then run from the respective responsibility

> Last step to Bounce the apache server from the application tier  $INST_TOP/admin/scripts
./adapcctl.sh  stopall
./adapcctl.sh  startall

Done :)
 

Insert a new record

Here we will create an another page and call from search page and do create another record or update the record in update page and return back to the search page.

1> Create an edit icon
Right click on table type object and create a new item of type image, change below properties
Item style    > image
Prompt        > Edit
Image URL > updateicon_enabled.gif 
(These images are there in C:\Jdeveloper\jdevhome\jdev\myhtml\OA_MEDIA)
Action Type > fireaction
Event > updateRecord
Parameters > create parameter which can be primary key, here I am creating based on these two columns
PPensionOption     ${oa.xxhwHrNicVO1.PensionOption}
PLowerLimit         ${oa.xxhwHrNicVO1.LowerLimit}


2> Create an update page
     >> /xxhw/oracle/apps/per/nic/webui/xxhwHrNicUpdPG

ID                 > PageLayoutRN
Region Style > pageLayout
Use same CO and AM
Window Title and Title > Update National Insurance Contributions


3> Right click the layout region and create new region using wizard, select same AM and VO as the search page.


4> Set a new controller for new page, name it as 'xxhwHrNicUpdCO'


5> Create new 'messageComponentLayout' (ButtonRN) under it
     > and 'messageLayout' under it.


6. Create 4 items with property > submitButton

We will write the insert logic for 'Split' button


7> For 'Split' button set Action Type > fireaction and set parameters
     PSPensionOption   ${oa.xxhwHrNicVO1.PensionOption}
     PSLowerLimit         ${oa.xxhwHrNicVO1.LowerLimit}
     PSUpperLimit          ${oa.xxhwHrNicVO1.UpperLimit}
     PSNicPercentage  ${oa.xxhwHrNicVO1.NicPercentage}
     PSRebate               ${oa.xxhwHrNicVO1.Rebate}
     PSDescription       ${oa.xxhwHrNicVO1.Description}
     > These parameter values will be used for new record creration

 


8> Now it is time to write some logic.
Go to the controller of the main page and handle logic for the newly added 'Edit' icon.
In the processFormRequest of xxhwHrNicCO add below code

      //Logic for edit icon

     //Initialising attribute to get value of any event (Note we have added edit button as event)   
      String actionFired = pageContext.getParameter("event");
     //It will get parameter created in Edit button
      String PPensionOption = pageContext.getParameter("PPensionOption");
      String PLowerLimit = pageContext.getParameter("PLowerLimit");

//Now logic is:
if(actionFired.equals("updateRecord"))
       {
// create a hash map and put values for parameters and action
           HashMap phm = new HashMap();
           phm.put("xxPPensionOption", PPensionOption);
           phm.put("xxPLowerLimit", PLowerLimit);
           phm.put("xxActionOnRecord", actionFired);
           // go to update page
pageContext.setForwardURL("OA.jsp?page=/xxhw/oracle/apps/per/nic/webui/xxhwHrNicUpdPG", null, (byte)0, null, phm, true, "N", (byte)99);
       }

9> Run the page













10> Go



 11> Click on the edit icon and you can see the update page with one record









12> Now add logic to handle Edit and (Split Record or Insert) button

> Create a method ' updateRecordMethod' in Application Module  ' xxhwHrNicAMImpl'

    public void updateRecordMethod(String pAction, String PPensionOption, String PLowerLimit)
        {
            try
            {
                System.out.println("Inside xxhwHrNicAMImpl.updateRecordMethod");
                OAViewObjectImpl pervo = getxxhwHrNicVO1();
                String existingWhereClause = pervo.getWhereClause();
                pervo.setWhereClauseParams(null);
                pervo.setWhereClause("PENSION_OPTION = :1 AND LOWER_LIMIT = to_number(:2)");
                pervo.setWhereClauseParam(0, PPensionOption);
                pervo.setWhereClauseParam(1, PLowerLimit);
                pervo.executeQuery();
                pervo.setWhereClauseParams(null);
                pervo.setWhereClause(existingWhereClause);
            }
            catch(Exception exception1)
            {
                throw OAException.wrapperException(exception1);
            }
        }

> Now change the Controller of Update Page -- xxhwHrNicUpdCO

In the processrequest
> Get all the parameter values and execute query based on these parameters

  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
      super.processRequest(pageContext, webBean);
      String actionOnRecord = pageContext.getParameter("xxActionOnRecord");
      String PPensionOption = pageContext.getParameter("xxPPensionOption");
      String PLowerLimit = pageContext.getParameter("xxPLowerLimit");
      OAApplicationModule recAM = pageContext.getApplicationModule(webBean);
      Serializable recordParamList[] = {
          actionOnRecord, PPensionOption, PLowerLimit
      };
      if(actionOnRecord != null && actionOnRecord.equals("updateRecord"))
      {
          recAM.invokeMethod("updateRecordMethod", recordParamList);
      }
  }

>> Done with the Edit button logic.
>> Do the same for Cancel and Save button logic what you did in Main page

>> Now add logic for 'Split Record ' Button, it should create a new record with some values from parent record.

> Create another method insertRecord in Application Module xxhwHrNicAMImpl
    public void insertRecord(String PSPensionOption, String PSLowerLimit, String PSUpperLimit, String PSNicPercentage, String PSRebate, String PSDescription)
 
        {
            OAViewObjectImpl HrNicVOImpl = (OAViewObjectImpl)getxxhwHrNicVO1();
            Row hrnicrow = HrNicVOImpl.createRow();
           
            hrnicrow.setAttribute("PensionOption", PSPensionOption);
            hrnicrow.setAttribute("LowerLimit", 0);// PSLowerLimit);
            hrnicrow.setAttribute("UpperLimit", 0);//PSUpperLimit);
            hrnicrow.setAttribute("NicPercentage", PSNicPercentage);
            hrnicrow.setAttribute("Rebate", PSRebate);
            hrnicrow.setAttribute("Description", PSDescription);
            HrNicVOImpl.insertRow(hrnicrow);
            hrnicrow.setNewRowState((byte)-1);
            getTransaction().commit();
        }

>> Update the Processformrequest of the update page controller xxhwHrNicUpdCO

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    String actionFired = pageContext.getParameter("event");
    String PSPensionOption = pageContext.getParameter("PSPensionOption");
    String PSLowerLimit = pageContext.getParameter("PSLowerLimit");
    String PSUpperLimit = pageContext.getParameter("PSUpperLimit");
    String PSNicPercentage = pageContext.getParameter("PSNicPercentage");
    String PSRebate = pageContext.getParameter("PSRebate");
    String PSDescription = pageContext.getParameter("PSDescription");
   
      Serializable pcardList[] = {
                                  PSPensionOption, PSLowerLimit, PSUpperLimit, PSNicPercentage, PSRebate, PSDescription
                                 };   
   
      if (pageContext.getParameter("Save") != null)
      {
          am.getOADBTransaction().commit();
      }
      else if (pageContext.getParameter("Cancel") != null)
      {
          am.getOADBTransaction().rollback();
      }
// if retuen then return for Main page
      else if (pageContext.getParameter("Return") != null)
      {
          pageContext.setForwardURL("OA.jsp?page=/xxhw/oracle/apps/per/nic/webui/xxhwHrNicPG", null, (byte)0, null, null, true, "N", (byte)99);
      }
      // if splitrecord then call a insertrecord method with all the parameter values
      if(actionFired.equals("splitRecord"))
      {
          am.invokeMethod("insertRecord", pcardList);
      }
   
  }

13> Run the page again

On the update page click on 'Split Record' button










Change and save, return to the main page.
Done. :)

>> Now it's time to deploy your custom page and access from application
 

Adding list of values to a field

After adding the update functionality let add list of values to the search based column.

1> Create a new VO object for LOV
     > Project > New > Business Tier > ADF Business Components > View Object


2> Create LOV(xxhwOptLOV) in package xxhw.oracle.apps.per.nic.lov.server


3> Next


4> Next


5> Next and write a script for LOV in the expert mode, it is better to give alias to the selected column
     > Test the query
     > Click next .. next .. next and finish

select distinct pension_option pOpt
  from hw_custom.xxhw_hr_nic_data


6> Create an AM(xxhwLOVAM) for this LOV VO and attach the same


7> Select Generate Java Files for AM class


8> Now change the item style of item PensionOption to 'MessageLovInput'


9> It will create another region and item under it


10> Change ID(xxhwLovRN) and AM(xxhwLOVAM) definition of this newly created region


11> Now right click to region > New > table Using Wizard


12> Select AM(xxhwLOVAM) and VO


13> Next .. Next .. select view attribute


14> Change prompt


15> Change the property of LOV view attribute.
       >> Search allowed/ sort allowed


16> Do the mapping for lovmapping > lovMap1
       > LOV region Item(pOpt), Return Item(PentionOption), Criteria Item(PentionOption)


17> Compile and run the page

>> Next we will work on Inserting a new record

 

Create a simple update page

After creating a simple search page lets add simple update functionality to the same page.

1> Create a new button region


2> Change ID (ButtonRN) and region style(pageButtonBar)


3> Create a new item to this Button region



4> Change Id(Save), Item Style(submitButton), prompt(Save) and attribute set as
                       /oracle/apps/fnd/attributesets/Buttons/Apply


5> Create another item and Change Id(Cancel), Item Style(submitButton),
     prompt(Cancel) and attribute set as  /oracle/apps/fnd/attributesets/Buttons/Cancel


6> Since we need to write some command update functionality now we will add a page controller


7> Name xxhwhrnicCO under webui package


8> Now we need to write some logic for update functionality, add below methods to the AMImpl file
     (xxhwhrnicAMImpl) for commit or rollback the changes.

public void apply()
    {
     getTransaction().commit();
    }

public void rollback()
    {
     getTransaction().rollback();
    }


9> Call these methods from controller(xxhwhrnicCO) for update logic
     Import below beans and replace processRequest and processFormRequest methods
     with below logic.
    I guess logic is self explanatory :)

import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.layout.OAQueryBean;

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAQueryBean queryBean = (OAQueryBean)webBean.findChildRecursive("QueryRN");
queryBean.clearSearchPersistenceCache(pageContext);
}
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if (pageContext.getParameter("Save") != null)
{
am.invokeMethod("apply");
pageContext.forwardImmediately("OA.jsp?page=/xxhw/oracle/apps/per/nic/webui/xxhwhrnicPG ",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
else if (pageContext.getParameter("Cancel") != null)
{
am.invokeMethod("rollback");
pageContext.forwardImmediately("OA.jsp?page=/xxhw/oracle/apps/per/nic/webui/xxhwhrnicPG ",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
}

> In case any error populates to import some packages, just import those



 >> Lets add list of values (LOV) to our search column Adding LOV
 

Friday, January 10, 2014

Create a Simple Search Page


After doing the initial setup we will now create a simple search page.

1> Create a database Connection EX: AKDEV
      > Connections Navigator
      > Connection > New Database Connection
       > It will launch Create Database Connection Wizard
          > Click on Next and give the Connection Name


       > Provide the database access details and check 'Deploy Password'

 
       > Provide connection details from dbc file

 
       > Test the connection

       > Create a new workspace
          > Applications Navigator
          > Applications > New OA Workspace...


       > Workspace name (Ex: AKOAWorkspace.jws)
    Note: Directory name will be defaulted based on your JDEV_HOME environment variable setting


          > Provide the Project name and default package name
            (Ex: XXHWOAProject
                  : xxhw.oracle.apps..per.nic.schema.server -- please follow the naming convention)
 

          > Choose the database connection created above


        > Select appropriate dbc file.


        > Provide the application user access details and application short name and responsibility key.
Note: Responsibility should be attached to the user.


   
          > Done with Project wizard

         > Update Project property
            > Oracle Applications > Run Options > OaDeveloperMode and OADiagnostic

           > Now we will create an Entity object to the project created
              > New > Business Tier > ADF Business Components > Entity Objects



          > Provide entity name (xxhwhrnicEO), package (xxhw.oracle.per.nic.schema) and
             database  Object (hw_custom.xxhw_hr_nic_data)

***Sometimes database schema name and schema object field is not enabled.
Do the following steps:
1. Before trying to create the EO, first open New > Business tier > ADF Business Components > Business Components from Tables.
2. Click OK and it will ask you to connect.
3. Connect and then cancel out of the wizard and try again.

         > Next

        > Make any column as primary key else by default it will make rowid as primary key


           > Select Generate Java File under Entity Collection and Entity Object class
              and Accessors, create method and Remove Method

         > Lets create a View object (xxhwhrnicVO) in this wizard only in
            package xxhw.oracle.apps.per.nic.server

           > Done with EO




                > Adding an Application Module (xxhwhrnicAM)
                   > Project > New > Business Tier > Application Module

                     Package as same as the VO xxhw.oracle.apps.per.nic.server

                   > Attach the above created VO to the AM



              > Select Generate Java Class for AM Class and done with AM



                 
 >> We will create a search page now
          > Project > New > Web Tier > OA Components > Page

          > Page name (xxhwhrnicPG) under package (xxhr.oracle.apps.per.nic.webui)




                  > Change ID (PageLayoutRN) and AM definition (Above Created AM),
                      Window Title and Title (Ex: National Insurance Contribution) of the page


            > Now add Query region and Result table
               > Page > New > Region


                > Change ID(QueryRN) Region Style(query) and Construction Mode(ResultsBasedSearch)

                > Create New region using wizard to the QueryRN

          > Select AM and VO

          > Select region style as 'Table'


           > Select appropriate columns from table



             >  Change Prompt and style
                  >> Change style to messagestyledtext if you want to make the column
                        un-updatable, else messageTextInput


               > Finish




            > Make the changes for columns for search Allowed/sort allowed


                > Now compile the page



            > It may give error for who columns methods missing in EOImpl class like below

Error(17,14): class xxhw.oracle.apps.per.nic.schema.xxhwhrnicEOImpl should be declared abstract; it does not define method setLastUpdateLogin(oracle.jbo.domain.Number) of class oracle.apps.fnd.framework.server.OAEntityImpl


          > Add below codes to EOImpl java file (xxhwhrnicEOImpl.java)

public void setLastUpdateLogin( oracle.jbo.domain.Number n ) {}
public void setLastUpdateDate( oracle.jbo.domain.Date n ) {}


            > Save all and run the page again
            > Click on 'Go', it should show all the relevant data


>> Lets add some update functionality to this page Create a simple update page