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);
    }
}

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 

}
}