Saturday, October 6, 2012

OAF Dialog Page Options

OAF Dialog Page Options


Dialog Style 1
OAException message = new OAException("File does not exist.",OAException.ERROR); 
pageContext.putDialogMessage(message);



Dialog Style 2 Information Ok
// To Diaplay the Exception on a Dialog page
OAException message = new OAException("File created successfully.");
OADialogPage dialogPage = new OADialogPage(OAException.CONFIRMATION, message, null, "",null);
dialogPage.setOkButtonToPost(true);
dialogPage.setOkButtonLabel("Ok");
dialogPage.setPostToCallingPage(true);
java.util.Hashtable formParams = new java.util.Hashtable(1);
dialogPage.setFormParameters(formParams);
pageContext.redirectToDialogPage(dialogPage);




Dialog Style 3 Yes No OAException message = new OAException("Do you want t create new record ?");
OADialogPage dialogPage = new OADialogPage(OAException.INFORMATION, message, null, "",null);
      String yes = pageContext.getMessage("AK", "FWK_TBX_T_YES", null);
      String no = pageContext.getMessage("AK", "FWK_TBX_T_NO", null);
      dialogPage.setOkButtonItemName("SaveYesButton");
      dialogPage.setNoButtonItemName("SaveNoButton");
      dialogPage.setOkButtonToPost(true);
      dialogPage.setNoButtonToPost(true);
      dialogPage.setPostToCallingPage(true);
      dialogPage.setOkButtonLabel(yes);
      dialogPage.setNoButtonLabel(no);
      pageContext.redirectToDialogPage(dialogPage);


      if (pageContext.getParameter("SaveYesButton") != null)
        {
          // Write Action code for Yes Button             
        }
                 if (pageContext.getParameter("SaveNoButton") != null)
                   {
          // Write Action code for No Button           
                   }




References
http://mukx.blogspot.com/2007/06/extensions-in-oa-framework-by-mukul.html
http://imdjkoch.wordpress.com/2012/05/25/oaexception-message-and-dialog-page-in-oa-framework/
http://zett7.blogspot.com/2010/12/passing-parameters-to-dialog-page-oaf.html
http://appsoracle-abhi.blogspot.com/2011/12/creating-search-insert-update-delete-on.html



OAF Upload Blob File in Table Column

 OAF Upload Blob Table Column

1)Create OA Page.
2)Add AM Defn to pageLayoutRN.
3)Create StackRegion or any required base layout region. (optional)
4)Add form Region with columns as



5)Change Attached File         a)Remove View instance and View Attribute b)  Data type to BLOB.


6)Create controller  on PageLayout RN.

7)Inside AMimpl   add below code
**********************************************************
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;

import oracle.jbo.Transaction;

      public void createAttach()
      {
        OAViewObject vo = (OAViewObject)getXxFileBlobsVO1();
        // Per the coding standards, this is the proper way to initialize a   
        // VO that is used for both inserts and queries.  See View Objects   
        // in Detail in the Developer's Guide for additional information.       
        if (!vo.isPreparedForExecution())    
        {      
            vo.executeQuery();    
        }
        Row row = vo.createRow();   
        vo.insertRow(row);
       // Required per OA Framework Model Coding Standard M69
       row.setNewRowState(Row.STATUS_INITIALIZED);
      } // end createAttach() 

public void apply()
{
  getTransaction().commit();
} // end apply()
**********************************************************


8)In Controller processRequest add below code
**********************************************************
import oracle.apps.fnd.framework.OAApplicationModule;
..
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      am.invokeMethod("createAttach", null);
**********************************************************


9)Add createBlobDomain  method inside Controller.
**********************************************************
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.domain.BlobDomain;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.sql.SQLException;
..
 private BlobDomain createBlobDomain(DataObject pfileUploadData)
{
    // init the internal variables
        InputStream in = null;
        BlobDomain blobDomain = null;
        OutputStream out = null;
       
    try
    {
        String pFileName =
        (String) pfileUploadData.selectValue(null,"UPLOAD_FILE_NAME");
        BlobDomain uploadedByteStream = (BlobDomain)pfileUploadData.selectValue(null,pFileName);
        // Get the input stream representing the data from the client
        in = uploadedByteStream.getInputStream();
        // create the BlobDomain datatype to store the data in the db
        blobDomain = new BlobDomain();
        // get the outputStream for hte BlobDomain
        out = blobDomain.getBinaryOutputStream();
        byte buffer[] = new byte[8192];
            for(int bytesRead = 0; (bytesRead = in.read(buffer, 0, 8192)) != -1;)
                out.write(buffer, 0, bytesRead);
            in.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (SQLException e)
    {
        e.fillInStackTrace();
    }
    // return the filled BlobDomain
    return blobDomain;
}
**********************************************************


10)Add below piece of code inside processForm Request
**********************************************************
import oracle.apps.fnd.framework.OAViewObject;
import oracle.jbo.Row;
..
// Select file then hit commit
          if (pageContext.getParameter("CommitBtn") != null)
            {
           
                OAViewObject vo = (OAViewObject)am.findViewObject("XxFileBlobsVO1");
                oracle.jbo.domain.Number fileId = (oracle.jbo.domain.Number)vo.getCurrentRow().getAttribute("FileId");
                Row row = (Row)vo.getCurrentRow();
               
                DataObject fileUploadData =
                                (DataObject)pageContext.getNamedDataObject("AttachedFile");
                               
                               
                if(fileUploadData != null)
                    {
                      String uFileName =
                      fileId.toString()+"_"+(String) fileUploadData.selectValue(null,"UPLOAD_FILE_NAME");
                      String contentType =
                      (String)fileUploadData.selectValue(null,"UPLOAD_FILE_MIME_TYPE");
                      row.setAttribute("AttachedFile", createBlobDomain(fileUploadData));
                      row.setAttribute("AttachedFileName", uFileName);
                      row.setAttribute("Contenttype", contentType);
                    } 
                    // File Upload Ends
      
            am.invokeMethod("apply"); 
                String fileName = (String)vo.getCurrentRow().getAttribute("AttachedFileName");
                OAException confirmMessage = new OAException("File "+fileName+" uploaded succesfully .",OAException.CONFIRMATION);              
            pageContext.putDialogMessage(confirmMessage);                   
}
**********************************************************






Note:
You can set the profile option called UPLOAD_FILE_SIZE_LIMIT to specify the maximum size of the file
a user can upload. For example, if you set UPLOAD_FILE_SIZE_LIMIT to 500K, then during the http POST
request, OA Framework reads only up to 500K from the stream and throws an exception if the uploaded file is
larger than 500K.


To Upload File into Standard FND_LOBS  table
http://robertjungerius.wordpress.com/2011/04/08/building-a-generic-upload-page-in-oa-framework/



For

OAF Page to Upload Files into Server from local Machine

https://blogs.oracle.com/prajkumar/entry/oaf_page_to_upload_files
http://mukx.blogspot.com/2010/01/upload-file-to-application-server-using.html
http://mystuffoaf.blogspot.com/2012/03/uploading-file-into-server-from-local.html?zx=61db5b806994d831


Thursday, August 23, 2012

ADF Get sequence next value

Get sequence next value in ADF

Value Type :  Expression

Value :
(new oracle.jbo.server.SequenceImpl("HR.XX_IMAGE_S",adf.object.getDBTransaction())).getSequenceNumber()









Other options mentioned in
http://hasamali.blogspot.com/2011/04/adf-bc-various-way-of-setting-sequence.html


For Programmatic Approach
in EoImpl

import oracle.jbo.server.SequenceImpl;
...
protected void initDefaults() {
super.initDefaults();

SequenceImpl sequence = new SequenceImpl("<YourSequenceName>",getDBTransaction());
DBSequence dbseq = new DBSequence(sequence.getSequenceNumber());
OR
Number seqValue = (Number)sequence.getSequenceNumber();
populateAttributeAsChanged(<YourId>,dbseq
}




OR

Inside  EOImpl Class
@Override
public void create(AttributeList attributeList) {
super.create(attributeList);
SequenceImpl seq = new SequenceImpl("LOG_SEQ", getDBTransaction());
Number seqNextval = seq.getSequenceNumber();
setId(seqNextval);
}


Saturday, August 18, 2012

OAF Get Oracle Date FOrmat / Change Date Format

1) From one format to any other format

eg.   15-Aug-2012    to  12/08/15
        String dob;
        dob = "15-Aug-2012 ";
        final String OLD_FORMAT = "dd-MMM-yyyy";
        final String NEW_FORMAT = "yy/MM/dd";
        String  NewDate ;
        NewDate = "";
          if (dob != null) {
            try {
              SimpleDateFormat OldDateFormat = new SimpleDateFormat(OLD_FORMAT);
              Date dt = OldDateFormat.parse(dob);
              OldDateFormat.applyPattern(NEW_FORMAT);
              NewDate = OldDateFormat.format(dt);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
       
        System.out.println("Reqd Date Format is  :" + NewDate);


2) To get Oracle Date Format
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;

        // Inside PR or PFR
        String dob;
        dob = "15-Aug-2012 ";
       // Method Call
       oracle.jbo.domain.Date jboRateStart = castToJBODate(dob);
       System.out.println("JBO Date is  :" + jboRateStart);


      public static  oracle.jbo.domain.Date castToJBODate(String aDate) {
        DateFormat formatter;
        java.util.Date date;
        if (aDate != null) {
            try {
                formatter = new SimpleDateFormat("dd-MMM-yyyy");
                //formatter = new SimpleDateFormat("MM/dd/yyyy");
                date = formatter.parse(aDate);
                java.sql.Date sqlDate = new java.sql.Date(date.getTime());
                oracle.jbo.domain.Date jboDate =
                    new oracle.jbo.domain.Date(sqlDate);
                return jboDate;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

Output
JBO Date is  :2012-08-15

Split Characters with Specific Length


public class Split2CharFinal 
{
  public static void main(String[] args)
  {
             // You can put main method code in Process Request or Process Form Request
              String str = "SplitChar2";
              //  Split String with fixed Number of Char eg. 2 
              Object[] strOut;
              // Call Method to get Splitted String in Array 
              strOut = splitInParts(str, 2); 
 
              String str_Full_Split = "";
              // Read Array
              for (int i=0; i<strOut.length; i++) {
              System.out.println("  Out "+i+" "+strOut[i]);
              str_Full_Split = str_Full_Split +"/"+ strOut[i];
              } 
              System.out.println(" Full Split "+ str_Full_Split);
  } 
 
public static String[] splitInParts(String s, int partLength) {     
  int len = s.length();      
 
  // Number of parts     
  int nparts = (len + partLength - 1) / partLength;     
  String parts[] = new String[nparts];      
 
  // Break into parts     
    int offset= 0;     
    int i = 0;     
    while (i < nparts)     {         
      parts[i] = s.substring(offset, Math.min(offset + partLength, len));         
      offset += partLength;         
      i++;     
      }      
      return parts; 
    }  
}

Sunday, August 12, 2012

ADF Default Date as Sysdate


Go to Entity Object
Open Date Attribute which you want to Deafult as Sysdate
Click Value Type as Expression.
Value  adf.currentDate

For Timestamp adf.currentDateTime


import oracle.jbo.domain.Date;
..
protected Date getCurrentDate()
{
    return new Date( Date.getCurrentDate());
}
import oracle.jbo.Domain.Date;
import java.sql.Timestamp;
..
protected Date getCurrentDateWithTime()
{
    return new Date( new Timestamp( System.currentTimeMillis()));
}




http://abakalidis.blogspot.com/2007/02/oracle-adf-accessing-current-date-and.html



Date Validations
http://mychanneladf.blogspot.com/2012/06/comparing-dates-and-displaying.htmlhttp://oracleanil.blogspot.com/2009/04/itemco.html
 

Sunday, July 8, 2012

ADF PPR Checkbox(af:selectBooleanCheckbox) action hide/show Command Link (af:commandLink)


Requirement

On ADF Form after Clicking Accept Terms and Condition Checkbox(af:selectBooleanCheckbox) make another component eg. Command Link (af:commandLink)  visible or enable using Partial Page Rendering.



After Accepting T&C show Command Link Available Options




Solution 
On ADF Page create Terms and Condition Checkbox
1)Enter Label and/or other details
2)In Property Inspector à Behavior à Auto Submit to True
3)In Property Inspector à Behavior à Value Change Listener to create method  TCcheckUncheck



4)In Property Inspector àAdvanced à Bindings click edit to create New tcCheckBox


 
<af:selectBooleanCheckbox text="Accept T&amp;C"
                                        label="Accept" id="sbc1"
                                        autoSubmit="true"
                                        valueChangeListener="#{IATLoginMB.TCcheckUncheck}"
                                        binding="#{IATLoginMB.tcCheckBox}"/>

Create Command Link with appropriate URL or Action
1)Enter Label and/or other details
2) In Property Inspector àAdvanced à Bindings click edit to create New myLink1


3) ) In Property Inspector àAdvanced àVisible to False
              <af:commandLink text="Available Options" action="taskflowLogin1"
                              id="cl1"
                              binding="#{IATLoginMB.myLink1}" visible="false"/>

Below Code in Managed Bean

    private RichSelectBooleanCheckbox tcCheckBox;
    private RichCommandLink myLink1;

 public void TCcheckUncheck(ValueChangeEvent valueChangeEvent) {

        if(this.getTcCheckBox().isSelected() == true ) {
            System.out.println("Checked ");
            myLink1.setVisible(true);
        }
       else if(this.getTcCheckBox().isSelected() == false ){
            System.out.println("UnChecked ");
            myLink1.setVisible(false);
             }

        AdfFacesContext.getCurrentInstance().addPartialTarget(myLink1);

    }

   public void setTcCheckBox(RichSelectBooleanCheckbox tcCheckBox) {
        this.tcCheckBox = tcCheckBox;
    }

   public RichSelectBooleanCheckbox getTcCheckBox() {
        return tcCheckBox;
    }

    public void setMyLink1(RichCommandLink myLink1) {
        this.myLink1 = myLink1;
    }

    public RichCommandLink getMyLink1() {
        return myLink1;
    }

Monday, June 25, 2012

ADF Call Stored Procedure with Out Parameters



Step1  Create DB Procedure
stored_db_proc(Param1 IN VARCHAR2,
                           Param2 IN DATE,
                           x_errCode OUT VARCHAR2,
                           x_errMsg OUT VARCHAR2);

Step 2  Create Public/Protected method in ApplicationModule to call

import oracle.jbo.server.DBTransaction; 
public String[] callStoredProcOutParam(String p_param1,String p_param2Date) {
String _xErrCode;
String _xErrMsg;
DBTransaction trx =(DBTransaction)getTransaction(); 
CallableStatement st = null;
try  {
// 1. Define the PL/SQL block for the statement to invoke
String stmt = "begin stored_db_proc (?,?,?,?); end;";
// 2. Create the CallableStatement for the PL/SQL block
st = trx.createCallableStatement(stmt,0);
// 3. Register the positions and types of the OUT parameters
st.registerOutParameter(3,Types.VARCHAR);
st.registerOutParameter(4,Types.VARCHAR);
// 4. Set the bind values of the IN parameters
st.setObject(1,p_param1);
st.setObject(2, p_param2Date);
// 5. Execute the statement
st.executeUpdate();
//6. Set value of _xErrCode  property using first OUT param
_xErrCode =  st.getString(3);
//7. Set value of _xErrMsg property using 2nd OUT param
_xErrMsg =  st.getString(4); 
// 8. Return the result
return new String[] {_xErrCode,_xErrMsg} ;
} catch (SQLException e)  {
                             throw new JboException(e);
} finally  {
if (st != null) {
try {
// 9. Close the JDBC CallableStatement
st.close();
}
catch (SQLException e) {
e.getStackTrace();

}
}
}
}



Step3    Expose callStoredProcOutParam method in PageDefBindings

 Add method in Application Module Client

                Double click AppMOdule àCkick Java à Client Interface

(Note : This will add Interface
public class csvAMClient extends ApplicationModuleImpl implements csvAM)

Refresh Data Control to see newly added  method.

Open Page Def Bindings, Click + Button , Select Method Action,


Click on DataControl Select Method to be included.




Step 4 In Managed Bean Listner method
import oracle.binding.DataControl;
            import oracle.binding.OperationBinding; 
import oracle.adf.model.BindingContext;
            import oracle.adf.model.binding.DCBindingContainer;
........
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();

DCBindingContainer binding = (DCBindingContainer) app.evaluateExpressionGet(context, "#{bindings}",DCBindingContainer.class);

// Call AM insContData Method

OperationBinding callAmMethod =
binding.getOperationBinding("callStoredProcOutParam ");
callAmMethod.getParamsMap().put("p_param1",Val1);

callAmMethod.getParamsMap().put("p_param2Date ",castToJBODate(Val2));

callAmMethod.execute();

       

        Object ReturnValue[] = (Object[])callAmMethod.getResult();

       

        String _errCode = (String)ReturnValue[0];

        String _errMsg  = (String)ReturnValue[1];

 

 

 

 
For more Information

37.5 Invoking Stored Procedures and Functions