Friday, 11 July 2014

Shuttle Region in OAF

Shuttle region allows users to move items between two lists as well as reorder the items in the list. When you implement a Shuttle region, you define two lists:


A Leading list (Available List) - from which user can select items from a given list of items
A Trailing list (Selected List) - user will select item from Leading list and move those to this trailing list.

Also we can implement a Shuttle region with just one list, to achieve only Reorder functionality, in that case only a Leading list is required.

We can also add buttons/icons in the footer below each of the Shuttle lists. By Simply defining Leading footer child or Trailing footer child in region creates a flowLayout region by default, to which we can add a button or image.

Here, I have created a simple page to implement shuttle region. User will select employee name from 'Available List' and move them to 'selected List'. A button is also added at footer of trailing list. Clicking on this button will show all the employees selected in a message.

1) Create a new OA page:
=========================
Right click on project (xxcus) --> New --> Web Tier --> OA Components --> select 'Page' item. Click OK. (This will open a popup window)
We are creating a page for implementing shuttle region, so specify the details of page as below:
          Name: XxShuttleDemoPG
          Package: xxcus.oracle.apps.fnd.shuttledemo.webui

2) Create a new view objects (VO):
=========================
Right click --> New View Object (This will open a wizard having 7 steps).

Step 1
         Package: xxcus.oracle.apps.fnd.shuttledemo.server
         Name: XxEmpShuttleVO
         Choose the radio button 'Read-only Access' (as there is no DML operation). Click Next.

Step 2
         Enter the below query in 'Query Statement':
               select ename from employee

Keep defaults for step3, 4, 5, 6 & 7 and click Finish. Save All.   

3) Create a new Application Module (AM):
=========================

Step 1
         Package: xxcus.oracle.apps.fnd.shuttledemo.server
         Name: XxShuttleDemoAM. Click Next.

Step 2
    Here we will add an instance of the VO created in (2). Select XxEmpShuttleVO from 'Available View Objects' and shuttle it to 'Data Model' using ">" button.

Keep defaults for all other steps (3, 4). Click Finish.

4) Create a new Controller (CO):
=========================
Right click on pageLayout region and create a new controller
            Name: XxShuttleDemoCO
            package: xxcus.oracle.apps.fnd.shuttledemo.webui


5) Creating the Page Layout & Setting its Properties :-
==========================
The page will appear as below:



1) Create a new region under pageLayout of type shuttle. This will automatically create a region for leading list.
2) Add Trailing list: right click shuttle region --> new --> Trailing.
3) Add trailing footer to display button: Again right click on shuttle region --> new --> trailingFooter. This will create a flowLayout region under trailingFooter.
4) Add 'Display Items' button: Create an item of type submitButton under the flowLayout region.

Now change the properties for each field from property inspector as shown below:


pageLayout:
            ID: pageLayoutRN
            AM Definition: xxcus.oracle.apps.fnd.shuttledemo.server.XxShuttleDemoAM
            Window Title: Shuttle Demo Page
            Title: Shuttle Demo

shuttle:
           ID: shuttleRN
           Available Header: Available Employees
           Selected Header: Selected Employees


leadingList:
           Picklist View Definition: xxcus.oracle.apps.fnd.shuttledemo.server.XxEmpShuttleVO
           Picklist View Instance: XxEmpShuttleVO1
           Picklist Display Attribute: Ename
           Picklist Value Attribute: Ename

list2:
           Picklist Display Attribute: Ename
           Picklist Value Attribute: Ename

submitButton:
           ID: displayBtn
           Prompt: Display Items

The declarative page structure in jDev will be similar to as shown below:


We will catch the button event (displayBtn) in PFR method of controller and display a message showing all the employees present in selected list. If there is no item in selected list, throw an error message. Below is code for the same:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public void processFormRequest(OAPageContext pageContext,
                               OAWebBean webBean) {
    super.processFormRequest(pageContext, webBean);
     
    String message = "";
     
    if (pageContext.getParameter("displayBtn") != null) {
        OADefaultShuttleBean shuttle =
            (OADefaultShuttleBean)webBean.findChildRecursive("shuttleRN");
        String[] items =
            shuttle.getTrailingListOptionValues(pageContext, shuttle);
     
    if (items != null) {
            for (int i = 0; i < items.length - 1; i++) {
                message = items[i] + " , " + message;
            }
             
            message = message + items[items.length - 1];           
            throw new OAException("Items in trailing list are: " +
                                  message, OAException.INFORMATION);
        } else {
       throw new OAException("Please shuttle at least one item from available list.",
                                  OAException.ERROR);
        }
    }
}

Below is how the error message will appear:


Monday, 7 July 2014

Dependent Poplist in table

 Create Department poplist VO

Master VO: select dname,deptno from dept


Create Emplyee  Poplist VO

Child VO:

select ename,empno from emp where deptno=:1

Write below code  under controller  for dependent poplist in table level.

In Process Request
-----------------------
OATableBean tableBean=(OATableBean)webBean.findchildRecursive("TableBean");
OAMessageChoiceBean omcb1=(OAMessageChoiceBean)tableBean.findIndexedChildRecursive("Department");
OAMessageChoiceBean omcb2=(OAMessageChoiceBean)tableBean.findIndexedChildRecursive("Employee");
omcb1.setPickListCacheEnabled(false);
omcb2.setPickListCacheEnabled(false);
omcb2.setListVOBoundContainerColumn(0,tableBean,"Department");


In ProcessFormRequest
---------------

if("event".equalse(pageContext.getParameter(EVENT_PARAM))
{
Initilize ChildVO
childvo.executeQuery();
}





Sunday, 4 May 2014

change date to Specified formats

public class changeDateFormatCO extends OAControllerImpl {
    public changeDateFormatCO() {
    }
    public void processRequest(OAPageContext pageContext,OAWebBean webBean) {
super.processRequest(pageContext,webBean);
Calendar cal=Calendar.getInstance();
Locale locale = new Locale("en", "US", "WIN"); 
String date=dateFormat(cal.getTime(),0,locale);
}
    public void processFormRequest(OAPageContext pageContext,OAWebBean webBean) {
super.processFormRequest(pageContext,webBean);
 }

public static String dateFormat(Date paramDate, int paramInt, Locale paramLocale)
  {
    String str = "";

    if (paramDate != null)
    {
      switch (paramInt) {
      case 0:
        SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyy/MM/dd", paramLocale);
        str = localSimpleDateFormat1.format(paramDate);
        break;
      case 1:
        SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("HH:mm:ss", paramLocale);
        str = localSimpleDateFormat2.format(paramDate);
        break;
      case 2:
        SimpleDateFormat localSimpleDateFormat3 = new SimpleDateFormat("HH:mm", paramLocale);
        str = localSimpleDateFormat3.format(paramDate);
        break;
      case 3:
        SimpleDateFormat localSimpleDateFormat4 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", paramLocale);
        str = localSimpleDateFormat4.format(paramDate);
        break;
      case 4:
        SimpleDateFormat localSimpleDateFormat5 = new SimpleDateFormat("EEEEE, MMMMM dd yyyy", paramLocale);
        str = localSimpleDateFormat5.format(paramDate);
        break;
      case 5:
        SimpleDateFormat localSimpleDateFormat6 = new SimpleDateFormat("EEE, MMM dd", paramLocale);
        str = localSimpleDateFormat6.format(paramDate);
        break;
      case 6:
        SimpleDateFormat localSimpleDateFormat7 = new SimpleDateFormat("EEE", paramLocale);
        str = localSimpleDateFormat7.format(paramDate);
        break;
      case 7:
        SimpleDateFormat localSimpleDateFormat8 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS", paramLocale);
        str = localSimpleDateFormat8.format(paramDate);
        break;
      case 8:
        SimpleDateFormat localSimpleDateFormat9 = new SimpleDateFormat("EEEEE", paramLocale);
        str = localSimpleDateFormat9.format(paramDate);
      }

    }

    return str;
  }
}

Convert Different Date Types to Oracle.jbo.domain.Date format


Below code help us to Change Different  Date to JBO Date format.

Calendar cal=Calendar.getInstance();
java.util.Date utilDate=   cal.getTime();      //will  return  Sysdate.
java.sql.Date sqlDate1 = new java.sql.Date(utilDate.getTime());
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate1);


SIT VALIDATION USING KeyFlexFileds


package xxtest.oracle.apps.per.selfservice.specialinformation.webui;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import oracle.apps.fnd.flexj.KeyFlexfield;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAKeyFlexBean;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.per.selfservice.specialinformation.webui.SitUpdateCO;
import oracle.apps.per.selfservice.common.SSHRParams;

public class XXKeyFlexFieldCO extends SitUpdateCO
{

    publicXXKeyFlexFieldCO()
    {
    }

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

    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    {
        OAApplicationModule am = oapagecontext.getRootApplicationModule();
        SSHRParams sshrparams = new SSHRParams(am.getOADBTransaction());
        String v_bg_id = sshrparams.getSelectedPersonBusinessGroupId();
        String surl = oapagecontext.getCurrentUrl();
        if (oapagecontext.isLoggingEnabled(1)) {
             oapagecontext.writeDiagnostics(this, "URL" + surl, 1);
            oapagecontext.writeDiagnostics(this,
                                         "OAFunc Id" + oapagecontext.getFunctionId(),
                                         1);
        }

        String OAFunc = null;
        try {
            OAFunc =
                    surl.substring(surl.indexOf("OAFunc")).split("&")[0].split("=")[1];
        } catch (Exception e) {
            try {
                PreparedStatement pstmt =
                    am.getOADBTransaction().getJdbcConnection().prepareStatement("Select Function_name from fnd_form_functions where function_id=" +
                                                                                 oapagecontext.getFunctionId());
                ResultSet rs = pstmt.executeQuery();
                if (rs.next()) {
                    OAFunc = rs.getString(1);
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
                if (oapagecontext.isLoggingEnabled(1)) {
                        oapagecontext.writeDiagnostics(this, "URL" + surl, 1);
            oapagecontext.writeDiagnostics(this, "OAFunc" + OAFunc, 1);
        }

        if(oapagecontext.getParameter("HrNext") != null)
        {
                      if(OAFunc.equalsIgnoreCase("XXOLNG_CAR_LOAN_SS")||OAFunc.equalsIgnoreCase("XXOLNG_LEAVE_ENCASH_SS")||OAFunc.equalsIgnoreCase("XXOLNG_STAFF_LOAN_SS"))
                      {
            String From_Date = oapagecontext.getParameter("HrSitStartDate");
            String To_Date = oapagecontext.getParameter("HrSitEndDate");
            OAKeyFlexBean kffBean = (OAKeyFlexBean)oawebbean.findIndexedChildRecursive("HrSitKeyFlex");
            KeyFlexfield keyflexfield = (KeyFlexfield)kffBean.getAttributeValue(OAWebBeanConstants.FLEXFIELD_REFERENCE);
            oapagecontext.writeDiagnostics(this,"Segment Count:"+keyflexfield.getSegmentCount(),1);
            String s_struc_code = keyflexfield.getStructureCode();
            String str[] = new String[30];
            for(int i = 0; i < keyflexfield.getSegmentCount(); i++) {
                try

                    {

                       str[i] = keyflexfield.getSegment(i).getInputValue();
           
                    oapagecontext.writeDiagnostics(this, "segment"+i+"-"+keyflexfield.getSegment(i).getName()+"-"+str[i],1);

                     }
                     catch(Exception e)

                   {
                         str[i] = null;
                   }
            }

//
            String emp_id = (new StringBuilder()).append(oapagecontext.getEmployeeId()).append("").toString();
            String query = "SELECT hr_sit_validation.validate_segments(:1,:2,:3,:4, :5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18,:19,:20,:21,:22,:23,:24,:25,:26,:27,:28,:29,:30,:31,:32,:33,:34,:35) from dual";
            String rvalue = "N";
//
            try
            {
                PreparedStatement pStmt = am.getOADBTransaction().createPreparedStatement(query, 1);
                pStmt.setString(1, emp_id);
                pStmt.setString(2, s_struc_code);
                pStmt.setString(3, From_Date);
                pStmt.setString(4, To_Date);
//
                pStmt.setString(5, str[0]);
                pStmt.setString(6, str[1]);
                pStmt.setString(7, str[2]);
                pStmt.setString(8, str[3]);
                pStmt.setString(9, str[4]);
                pStmt.setString(10, str[5]);
                pStmt.setString(11, str[6]);
                pStmt.setString(12, str[7]);
                pStmt.setString(13, str[8]);
             //   oapagecontext.writeDiagnostics(this, "segment-"+keyflexfield.getSegment(8).getName()+"-"+str[8],1);
                pStmt.setString(14, str[9]);
                pStmt.setString(15, str[10]);
                pStmt.setString(16, str[11]);
                pStmt.setString(17, str[12]);
                pStmt.setString(18, str[13]);
                pStmt.setString(19, str[14]);
                pStmt.setString(20, str[15]);
                pStmt.setString(21, null);
                pStmt.setString(22, null);
                pStmt.setString(23, null);
                pStmt.setString(24, null);
                pStmt.setString(25, null);
                pStmt.setString(26, null);
                pStmt.setString(27, null);
                pStmt.setString(28, null);
                pStmt.setString(29, null);
                pStmt.setString(30, null);
                pStmt.setString(31, null);
                pStmt.setString(32, null);
                pStmt.setString(33, null);
                pStmt.setString(34, null);
                                pStmt.setString(35, v_bg_id);
//
                for(ResultSet rs = pStmt.executeQuery(); rs.next();)
                    if(rs != null)
                                        {
                        rvalue = rs.getString(1);
                                        }
                                            oapagecontext.writeDiagnostics(this,"rvalue--"+rvalue,1);
                                                          pStmt.close();
            }
            catch(Exception e)
            {
                throw OAException.wrapperException(e);
            }
//
            if ( rvalue.equals("N") )
            {
                String sContinue = "Y";
            }
            else
            {
                throw new OAException("XXTEST",rvalue,null,OAException.ERROR,null);
            }
            }
        }
        super.processFormRequest(oapagecontext, oawebbean);
    }
}