Sunday, September 7, 2008

ETC




NOT YET DOCUMENTED:


    public boolean isNumber(String num) {
        boolean flag = true;
        try {
            int spaceIndx = num.indexOf(" ");
            if (spaceIndx != -1) {
                flag = false;
            } else {
                Number n = new Number(num);
                if (n.doubleValue() <= 0.0) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }


-------------------------------------

       public String getEmpName(){
           Connection con = null;
           Statement stmt = null;
           ResultSet rs = null;
           String fName = null;
           try {
               con = ConnectionConn.getConnection();
               stmt = con.createStatement();
               String query = "Select First_Name from EMPLOYEES where EMPLOYEES_ID= '100'";
               rs = stmt.executeQuery(query);
               while(rs.next()){
                   fName = rs.getString("first_Name");
               }
           }
           catch(Exception e){
               e.printStackTrace();
           }
           finally{
               Utils.close(rs,stmt,con);
           }
           return fName;
       }

---------------------------------------

value="#{row.status != 111?'OPEN':''}"

value="#{bindings.status.inputValue == 'Active'? 'Yes' : 'No'}"

--------------------------------------


public class IndexBean {
    private RichTable empTable;
    private List selectedEmpArray = new ArrayList();
    private int modifiedRows = 0;
    private int newRows = 0;

   

    public void setModifiedRows(int modifiedRows) {
        this.modifiedRows = modifiedRows;
    }

    public int getModifiedRows() {
        return modifiedRows;
    }

    public void setNewRows(int newRows) {
        this.newRows = newRows;
    }

    public int getNewRows() {
        return newRows;
    }

    /**  RICH TABLE's SELECTION LISTENER
     * Get the selected rowKey
     * Add the rowKey to selectedEmpArray arrayList
     * @param selectionEvent
     */
    public void empSelectionEvent(SelectionEvent selectionEvent) {
        RowKeySet empRKS = selectionEvent.getAddedSet();
        if (empRKS.size() > 0) {
            Iterator empRKSIterator = empRKS.iterator();
            while (empRKSIterator.hasNext()) {
                Key key = (Key)((List)empRKSIterator.next()).get(0);
                if (!selectedEmpArray.contains(key)) {
                    selectedEmpArray.add(key);
                }
            }
        }
    }

    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

    /** COMMANDBUTTON COMMIT's ACTION LISTENER
     * While loop the selectedEmpArray
     * Get the entity status for the rowKeys
     * @param actionEvent
     */
    public void fetchModifiedRows(ActionEvent actionEvent) {
        if (selectedEmpArray.size() > 0) {
            //Resetting the row counts
            this.setModifiedRows(0);
            this.setNewRows(0);

            DCBindingContainer dcBindings = (DCBindingContainer)getBindings();
            DCIteratorBinding EmpsDCIterBinding = dcBindings.findIteratorBinding("EmployeesView1Iterator");
            RowSetIterator EmpsRSIter = EmpsDCIterBinding.getRowSetIterator();
            ViewObject vo = EmpsDCIterBinding.getViewObject();

            Iterator selectedEmpsIter = selectedEmpArray.iterator();
            while (selectedEmpsIter.hasNext()) {
                Row currentRow = EmpsRSIter.getRow((Key)selectedEmpsIter.next());
                EmpsRSIter.setCurrentRow(currentRow);

                ViewRowImpl myRow = (ViewRowImpl)vo.getCurrentRow();
                EntityImpl entityImpl = (EntityImpl)myRow.getEntity(0);
                if (EntityImpl.STATUS_MODIFIED == entityImpl.getEntityState()) {
                    this.setModifiedRows((this.getModifiedRows() + 1));
                } else if (EntityImpl.STATUS_NEW == entityImpl.getEntityState()) {
                    this.setNewRows((this.getNewRows() + 1));
                }
            }
        }
        commitAction();
    }

    /** CREATE BUTTON's ACTION LISTENER
     * CreateInsert new row and get rowKey for the added row
     * Add the rowKey to the selectedEmpArray arrayList
     * @param actionEvent
     */
    public void createNewRow(ActionEvent actionEvent) {
        BindingContainer bindings = getBindings();
        OperationBinding oper = bindings.getOperationBinding("CreateInsert");
        oper.execute();

        DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding EmpsIter = dcBindings.findIteratorBinding("EmployeesView1Iterator");
        EmployeesViewImpl eImpl = (EmployeesViewImpl)EmpsIter.getViewObject();
        if (!selectedEmpArray.contains(eImpl.getCurrentRow().getKey())) {
            selectedEmpArray.add(eImpl.getCurrentRow().getKey());
        }
    }

    public String commitAction() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        return null;
    }


}

------------------------------
  public String search(){

    String uName= null;
    FacesContext fctx = null;

    if(this.getInputText01().getValue() != null){
     
      uName = this.getInputText01().getValue().toString();
      }
      fctx = FacesContext.getCurrentInstance();
      ValueBinding userBrBind =
          fctx.getApplication().createValueBinding("#{bindings.VO1Iterator}");
      DCIteratorBinding userIter =
          (DCIteratorBinding)userBrBind.getValue(fctx);
      userIter.getViewObject().setNamedWhereClauseParam("uName",
                                                          uName);
      userIter.getViewObject().setWhereClause(null);
      userIter.executeQuery();
     
    this.getTable1().setRendered(true);
    return null;
    }
---
vBind = facesContext.getApplication().createValueBinding("#{bindings.EmployeesVO1Iterator}");
empIter = (DCIteratorBinding)vBind.getValue(facesContext);
empIter.getViewObject().setWhereClause(null);
empIter.executeQuery();
empIter.getViewObject().setWhereClause(" ( QRSLT.IS_DEL = 'Y' or QRSLT.IS_CENTER = 'Y' )and upper(QRSLT.BR) like upper ('%' ||'"+fromBr+"'"+" || '%')");
empIter.getViewObject().setOrderByClause("upper(QRSLT.BR)");
empIter.executeQuery();
    
-------------------------------
NOTE: Some times afterPhase() and beforePhase() will get executed multiple times. How to restrict them?
Solution:
    public void beforePhase(PhaseEvent phaseEvent){
      
        if(phaseEvent.getPhaseId().toString().equalsIgnoreCase("RENDER_RESPONSE 6")){

            onPageLoad();
           
            }
       
        }
   
    public void onPageLoad(){
        System.out.println("onPageLoad");
        }
-------------------------------Handling DC based on Bean---------
private String name;
private NUMBER age;
private boolean vehicle;
private ArrayList productDtls;

------------
Attribute Name="name" Type="java.lang.String"
Attribute Name="age" Type="oracle.sql.NUMBER"/
Attribute Name="vehicle" Type="boolean"/

AccessorAttribute id="productDtls" IsCollection="true" Type="java.util.ArrayList"
                     CollectionBeanClass="UpdateableCollection"
                     BeanClass="com.mb.test.productDtls"

------------

FacesContext fctx = FacesContext.getCurrentInstance();
Application appl = fctx.getApplication();
DCBindingContainer bindings =
                (DCBindingContainer)appl.getVariableResolver().resolveVariable(fctx,
                                                                               "bindings");
neelmaniDataMBean wMBean =
                (neelmaniDataMBean)bindings.getBindingContext().findDataControl("neelmaniDataMBean").getDataProvider();
---
                 VariableResolver varResol = null;
                 varResol = appl.getVariableResolver();
                 NeelmaniCustInfoBean neelInfo =   (NeelmaniBean)varResol.resolveVariable(fctx,  "backing_pages_customerInfo");
                
                 neelInfo.getInputText1().setDefaultFacet("def");

-----Array List type Attribute in Bean Based DC

accessorIterator id="productDtlsIterator" RangeSize="-1" Binds="productDtls"
                      DataControl="NeelmaniDataMBean"
                      BeanClass="com.mb.test.NeelproductDtlsDtls"
                      MasterBinding="neelmaniDataMBean_dataProvider_rootIter"

-
JUFormBinding pkgs =
                    (JUFormBinding)appl.createValueBinding("#{bindings}").getValue(fctx);
DCIteratorBinding pkgsIter = pkgs.findIteratorBinding("productDtlsIterator");

-------------------------------
import oracle.jbo.server.DBTransaction;
PreparedStatement stmt = null;

DBTransaction transaction = (DBTransaction)am.getTransaction();
stmt = transaction.createPreparedStatement("",1);
stmt.executeUpdate();
               
transaction.getTransaction().commit();
transaction.getTransaction().setClearCacheOnCommit(true);
transaction.clearVOCaches("testEO", true);
transaction.clearVOCaches("testEO", true);
--
DBTransaction transaction = (DBTransaction)am.getTransaction();
String query = "select age from employees where age = (?) and dept_id = (?)";
pSmt = dbTrans.createPreparedStatement(query,1);
pSmt.setString(1,"30");
pSmt.setString(2,"11");
ResultSet result = pSmt.executeQuery();
-------------------------------
    public static ApplicationModuleImpl getAMInstance(String AM) {
         
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext, "#{data."+AM+"DataControl.dataProvider}",
                                                Object.class);

            return (ApplicationModuleImpl)valueExp.getValue(elContext);
      
    }
-------------------------------
Jasper report tutorial
-------------------------------
BI Report Integration with ADF
-------------------------------

 

 

 

 

    private Date getOneDayLessThanCurrentDate(){
        // Initializing variables.
        Timestamp ts = null;
        try {
            // Get the Calendar instance.
            Calendar calendar = Calendar.getInstance();
            // Set the date that is to be used as reference.
            calendar.setTime(new java.util.Date());
            // Subtract the reference date by 1.
            calendar.add(Calendar.DAY_OF_MONTH, -1);
            // Set the time factor to 0. Only the date is required.
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            // Get the new date.
            java.util.Date jDt = calendar.getTime();
            ts = new Timestamp(jDt.getTime());           
           
        }
        catch (Exception e) {
            logger.severe(" Error - getOneDayLessThanCurrentDate() ", e);
        }finally{
            // Return the newly prepared date.
            return new Date(ts);   
        }
    }

---
(new oracle.jbo.server.SequenceImpl("DEPT_SEQ", adf.object.getDBTransaction())).getSequenceNumber() as String

---
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adf-naming-layout-guidelines-v2-00-1904828.pdf

----

#{requestScope['attributeKey']}

when "attributeKey" is the attribute having "."

------------------------------------
Copyright \u00a9
Resource bundle entry for Copyright symbol
___________________________
LoggedInUser---
String logedInUser = ((AppModuleImpl) getDBTransaction().getRootApplicationModule()).getUserPrincipalName();
if(){
logedInUser = "anonymous";
}
return logedInUser;

--------------------------------------

Post Changes

____________________________
To disable JAAS :
Edit adf-config.xml file

Set [authorizationEnforce="false" authenticationRequire="false"] for JaasSecurityContext
____________________________
Getting handle of Resource bundle programatically

 FacesContext fc = FacesContext.getCurrentInstance();
        ResourceBundle bundle = fc.getApplication().getResourceBundle(fc,"bundle_name");
        bundle.getString("resource_identifier");

__________________________________
af:goLink text=”#{row.EmailAddress}”
destination=”#{\”mailto:\”} #{row.EmailAddress}”
_____________________________

how to pass the arguments within JDeveloper:

Tools > Project Properties > Run/Debug > Edit Default Run Configuration (or create new one) > Launch Settings > Program Arguments - here you can put in arguments

-------------------------------------------- 
http://oracleadf-java.blogspot.in/2012/10/passing-parameter-in-xml-resource-and.html
---------------- 
 Refresh Whole Page Programatically---
    protected void refreshPage() {
    FacesContext fctx = FacesContext.getCurrentInstance();
    String refreshpage = fctx.getViewRoot().getViewId();
    ViewHandler ViewH = fctx.getApplication().getViewHandler();
    UIViewRoot UIV = ViewH.createView(fctx, refreshpage);
    UIV.setViewId(refreshpage);
    fctx.setViewRoot(UIV);
    }


---------------------------------- 


 "Low memory warning" on JDeveloper .


 There are two config files on jdeveloper installation directory.
the first one is jdev.conf file. the file located in \jdeveloper\jdev\bin
increase the memory values for the following parameters:
AddVMOption -XX:MaxPermSize=1024M

the second one is ide.conf file on \jdeveloper\ide\bin.

AddVMOption -Xmx1024M
AddVMOption -Xms1024M


---------------------------------------------------