Sunday, 4 May 2014

Programmatically Add the Fire Partical Action to a Bean

import oracle.cabo.ui.action.FireAction;

import oracle.cabo.ui.action.FirePartialAction;
 
public class XxFireActionExampleCO extends OAControllerImpl {
    public static final String RCS_ID = "$Header$";
    public static final boolean RCS_ID_RECORDED = 
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean); 
 
 OAMessageChoiceBean mb=(OAMessageChoiceBean)webBean.findChildRecursive("BeanId");

FireAction firePartialAction = new FirePartialAction("DelAction");

mb.setAttributeValue(PRIMARY_CLIENT_ACTION_ATTR,firePartialAction);
    /**
     * Procedure to handle form submissions for form elements in
     * a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);
if( "DelAction".equals(pageContext.getParameter(EVENT_PARAM))
{
 
// write Code Here 

}
} 


Tuesday, 22 April 2014

Table Horizant Scroll Bar

In order to lessen the pain of the user and to have better UI design, we will render scroll bars both horizontal and vertical just surrounding the table
as , shown in the image below :



So, now lets focus how can we bring these scroll bars. In that case you can use the DIV tag to do the job for you.Put 2 RawText Bean(named DivStart, DivEnd), before and after the Table Bean in the JRAD page as shown in the image below IN JDEVELOPER:



public class ScrollEnable extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
//SEE ALL PARAMETER values you need to pass in the java comments of the method
addScrollBarsToTable(pageContext, webBean,"DivStart","DivEnd",false,"1400",true,"400");
}
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
}
public void addScrollBarsToTable(OAPageContext pageContext,
OAWebBean webBean,
String preRawTextBean,
String postRawTextBean,
boolean horizontal_scroll, String width,
boolean vertical_scroll, String height)
{
String l_height = "1400";
String l_width = "400";
pageContext.putMetaTag("toHeight",
"<style type=\"text/css\">.toHeight {height:24px; color:black;}</style>");

OARawTextBean startDIVTagRawBean =
(OARawTextBean) webBean.findChildRecursive(preRawTextBean);
if (startDIVTagRawBean == null)
{
throw new OAException("Not able to retrieve raw text bean just above the table bean. Please verify the id of pre raw text bean.");
}

OARawTextBean endDIVTagRawBean =
(OARawTextBean) webBean.findChildRecursive(postRawTextBean);
if (endDIVTagRawBean == null)
{
throw new OAException("Not able to retrieve raw text bean just below the table bean. Please verify the id of post raw text bean.");
}

if (!((height == null) || ("".equals(height))))
{
try
{
Integer.parseInt(height);
l_height = height;
}
catch (Exception e)
{
throw new OAException("Height should be an integer value.");
}
}


if (!((width == null) || ("".equals(width))))
{
try
{
Integer.parseInt(width);
l_width = width;
}
catch (Exception e)
{
throw new OAException("Width should be an integer value.");
}
}

String divtext = "";
if ((horizontal_scroll) && (vertical_scroll))
{
divtext =
"<DIV style='width:" + l_width + ";height:" + l_height + ";overflow:auto;padding-bottom:20px;border:0'>";
}
else if (horizontal_scroll)
{
divtext =
"<DIV style='width:" + l_width + ";overflow-x:auto;padding-bottom:20px;border:0'>";
}
else if (vertical_scroll)
{
divtext =
"<DIV style='height:" + l_height + ";overflow-y:auto;padding-bottom:20px;border:0'>";
}
else
{
throw new OAException("Both vertical and horizintal scrollbars are passed as false,hence, no scrollbars will be rendered.");
}
startDIVTagRawBean.setText(divtext);
endDIVTagRawBean.setText("</DIV>");
}
}



In addScrollBarsToTable
Parameter1:OAPageContext object.
Paremeter 2:OAWebBean object
Paremter 3:Id of rawtext bean1
Parameter4:Id of rawtext bean2
Parameter 5:True will enable Horizontal Scroll Bar,No Will disable it.
Parameter6:1400 Size of the Table Extent to Apply  scroll bar
Parameter 7:True will enable Vertical Scroll Bar,No Will disable it.
Parameter8: 400 Size of the Table Extent to Apply  scroll bar

Usage of Record Type in Callable Statement

write below code under processFormRequest  based on your conditions.we can process record types using below Process

Import statement:
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
 import java.sql.SQLException;

String str[] = new String[30];

       for(int i = 0; i < 10; i++)

       try

     {

        str[i] = i;
      }
      catch(Exception e)

    {
          str[i] = null;
    }

  try
 {

   ArrayDescriptor segvaldesc = ArrayDescriptor.createDescriptor("SEGMENT_VALUES", connection);

   ARRAY segval = new ARRAY(segvaldesc, connection, str);

  OracleCallableStatement ocs = (OracleCallableStatement)connection.prepareCall("Begin  
   XXHR_SIT_VALIDATION_PKG.VALIDATE_RECORD 
  (p_sit_code=>:1,p_segment=>:2,p_person_id=>:3,p_employee_id=>:4,p_message=>:5); end;");

  ocs.setString(1, s_struc_code);
  ocs.setARRAY(2, segval);
  ocs.setString(3, v_person_id);
  ocs.setString(4, v_emp_id);
  ocs.registerOutParameter(5, 12);
  ocs.execute();

  v_message = ocs.getString(5);
  ocs.close();
 }
catch(SQLException sqlexception)
{
throw new OAException("Error " + sqlexception.getMessage(), (byte)2);
}

Making Attachement Mandatory

Need to make the Attachment Bean mandatory. Use the below line of code in PFR.

OAMessageAttachmentLinkBean oamessageattachmentlinkbean = (OAMessageAttachmentLinkBean)oawebbean.findChildRecursive("");

String attachVal = (String)oamessageattachmentlinkbean.getAttributeValue(oapagecontext.getRenderingContext(),TEXT_ATTR);

if("None".equals(attachVal))
{
throw new OAException(“Attachment mandatory”,OAException.ERROR);

Monday, 28 October 2013

Download BLOB File from Database

  Below code used to download BLOB File from database.

 Write Below Code Under Event ..


    String MimeType=null,FileName=null;
    String Rowref=pageContext.getParameter(EVENT_SOURCE_ROW_REFERENCE);
    OtherReportRequestVORowImpl row=(OtherReportRequestVORowImpl)am.findRowByRef(Rowref);
    try {
       String Query=" SELECT 'text/plain' MIME_TYPE, xxebex.xxebex_public.CLOB_TO_BLOB(REQUEST_LOG), 'InfoRequest_'||REQUEST_ID||'_ProcessLog.html' FILE_NAME"+
    " FROM xxebex.ebex_info_requests  WHERE request_id ='"+row.getRequestId()+"'";
    PreparedStatement cs=(PreparedStatement)am.getOADBTransaction().getJdbcConnection().prepareStatement(Query);
    ResultSet rs=cs.executeQuery();
    while(rs.next())
    {
        java.sql.Blob blob;
        blob = rs.getBlob(2);
        MimeType=rs.getString(1);
        FileName=rs.getString(3);
        int iLength = (int)(blob.length());
        System.out.println("Length:"+iLength);
        response.setHeader("Content-Disposition", "attachment; filename=\""+FileName+"\"");
        response.setContentType(MimeType);
        response.setContentLength(iLength);
        ServletOutputStream op = response.getOutputStream();
        op.write(blob.getBytes(1, iLength));
        op.flush();
        op.close();

    }
   
       
    }
    catch(Exception e) {
        System.out.println(e.getMessage());
    }


Wednesday, 18 September 2013

Export Data from Excel file to DataBase tables

Step 1: Create FileUpload Item  in Page
            Id:FileUploadItem
            Prompt:FileUpload
            DataType:Blob
Step 2:Create  a Submit Button
           Id:Go
          Prompt:Go
Step 3:Create a submit Button
           Id:Update
           Prompt:Update
           Event:update
Step 4:Write Following Code in controller i.e, attached to a page.

 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OAViewObjectImpl;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.cabo.ui.data.DataObject;

import oracle.jbo.Row;
import oracle.jbo.domain.BlobDomain;

/**
 * Controller for ...
 */
public class FileUploadCO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am=(OAApplicationModule)pageContext.getApplicationModule(webBean);
    OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject("DemoVO1");
    if (pageContext.getParameter("Go")!=null)
    {
    DataObject fileUploadData =(DataObject)pageContext.getNamedDataObject("FileUploadItem");
    String fileName = null;
    String contentType = null;
    Long fileSize = null;
    BlobDomain uploadedByteStream = null;
    BufferedReader in = null;
     
    try
    {
    fileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
    contentType =(String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
    uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, fileName);
    in = new BufferedReader(new InputStreamReader(uploadedByteStream.getBinaryStream()));   
     fileSize = new Long(uploadedByteStream.getLength()); 
    System.out.println("fileSize"+fileSize);
    }
    catch(NullPointerException ex)
    {
    throw new OAException("Please Select a File to Upload", OAException.ERROR);
    }
    try{     
    //Open the CSV file for reading  
    String lineReader="";

    long t =0;
     
     
    String[] linetext;
     
     
    while (((lineReader = in.readLine()) !=null) ){
     
     
    //Split the deliminated data and
    if (lineReader.trim().length()>0)
    {
    System.out.println("lineReader"+lineReader.length());
    linetext = lineReader.split(",");
    t++;  
    if(t>1)
{
    if (!vo.isPreparedForExecution()) {
    vo.setMaxFetchSize(0);
    vo.executeQuery();
    }
    Row row = vo.createRow();
    System.out.println("Column1->"+linetext[0]);
    row.setAttribute("VendorName", linetext[0]);
    row.setAttribute("Segment1",linetext[1]);
    row.setAttribute("VendorId",linetext[2]);
    
    vo.last();
    vo.next();
    vo.insertRow(row);
}
    }
     }
    }
     
     
    catch (IOException e)
    {
     e.printStackTrace();
    }
    }
    if ("update".equals(pageContext.getParameter(EVENT_PARAM))) {
    am.getOADBTransaction().commit();
    throw new OAException("Uploaded SuccessFully",OAException.CONFIRMATION);
     
     
    }
    }
    }
    



            

Saturday, 29 June 2013

Export Selected Rows into Excel File

1)Create ViewObject
 eg: EmpVO
Query:Select empno,ename,sal from scott.emp

2)Create Table by Region Using Wizard or manually with multiple Selection Option.
3)Create Transient attribute in EmpVO for Multiple Selection Option.i.e,xxselect type:String.
4)Create button  or Submit Button any where depend on The Requirement .
   Id:ExportBtn
  Prompt:Export
  Event:Export
5)Create a Controller under PageLayoutRN.

Write Below Code

public class EmpCO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");


  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
       EmpVOImpl vo=(EmpVOImpl )pageContext.getApplicationModule(webBean).findViewObject("EmpVO1");
    vo.executeQuery();
  }

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    if("Export".equals(pageContext.getParameter(EVENT_PARAM)))
    {
    EmpVOImpl vo = (EmpVOImpl)pageContext.getApplicationModule(webBean).findViewObject("EmpVO1");
      EmpVORowImpl row=(EmpVORowImpl)vo.first();
      Row[] row1=vo.getFilteredRows("xxselect","Y");
    try
    {

    HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
    response.setContentType("application/txt");
    response.setHeader("Content-Disposition","attachment; filename=" + "Employee Trouble Call Report" + ".csv");
    PrintWriter pw = null;
    pw = response.getWriter();

    //Writing the headers
    pw.write("Emploee Number");
    pw.write(",");
    pw.write("Employee Name");
    pw.write(",");
    pw.write("Salary");  
    pw.write("\n");
    // getting table data
    Row row2=null;
    System.out.println(row1.length);
       for(int i=0;i<row1.length;i++)//Read Selected Rows
       {
       row2=row1[i];
       String dept_name= row2.getAttribute("Empno").toString();
        String emp_name=row2.getAttribute("Ename").toString();
        String Salary=row2.getAttribute("Sal").toString();
         if(dept_name !=null) // for null handling in the code
         {
         pw.write(dept_name);
         }
         else
         {
         pw.write(" ");
         }
//      emp_name = emp_name.replaceAll(",",".");
           pw.write(",");
           if(emp_name!=null)
           {
          pw.write(emp_name);
           }
           else
           {
             pw.write("");
           }
         pw.write(",");//next cell
         if(Salary!=null)
         {
         pw.write(Salary);
         }
         else
         {
           pw.write("");
         }
           pw.write("\n");//next line
       }  
    pw.write(" ");
    pageContext.setDocumentRendered(false); //mandatory
    pw.flush(); //exporting data
    pw.close();

    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
  }
}