Monday, October 8, 2012

ADF: Resolving random JBO-27122 and closed statement errors


Problem: 
  • Resolving random JBO-27122 and closed statement errors 
  • <java.sql.SQLException: Statement cancelled, probably by transaction timing out.

Resolution:

Fusion web applications are not compatible with data sources defined with the JDBC XA driver. When creating a data source on Oracle WebLogic Server, be sure to change the Fusion web application data source's JDBC driver from “Oracle's Driver (Thin XA)” to “Oracle's Driver (Thin)”. Because XA data sources close all cursors upon commit, random JBO-27122 and closed statement errors may result when running the Fusion web application with an XA data source. 

Reference: http://docs.oracle.com/cd/E24382_01/web.1112/e16182/deployment_topics.htm#ADFFD23083

Thursday, July 5, 2012

ADF: Rendering HTML code on page


Below are the ways to render HTML code on JSF page:
  • Using <af:outputText>
  • <af:outputText value="#{pageFlowScope.testbean.value}" id="ot1"
                   escape="false"/>
    
  • Using <af:richTextEditor>
  • <af:richTextEditor label="Label 1" id="rte1" readOnly="true"
                       value="#{pageFlowScope.testbean.value}"/>
where bean code is using "org.apache.commons.lang.StringEscapeUtils.unescapeHtml" API to render html code properly.
import org.apache.commons.lang.StringEscapeUtils;

public class testbean {
    public testbean() {
    }
    
    private String value = "&lt;object width="100" height="100" data="http://www.google.co.in/images/srpr/logo3w.png"&gt;&lt;/object&gt;";

    public void setValue(String value) {
        this.value = value;
    }

    public String getValue() {
        value = StringEscapeUtils.unescapeHtml(value);
        return value;
    }
}

Tuesday, May 8, 2012

ADF: Programmatic View Criteria


To define view criteria programmatically:
  • VO must contain the attributes which are to be added in where clause.
  • The following method is added in AMImpl java class & method is exposed via client interface.
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaItem;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.domain.Number;
...
...

public void filterEmployees(){
   ViewObjectImpl empVOImpl = getEmployeesView1();            
   ViewCriteria vc = empVOImpl.createViewCriteria();
   ViewCriteriaRow vcr = vc.createViewCriteriaRow();            
    
   //criteria for employee id
   ViewCriteriaItem vci1 = vcr.ensureCriteriaItem("JobId");
   vci1.setValue("SH_CLERK");

   //criteria for showing employees whose salary are more than 10000
   ViewCriteriaItem vci2 = vcr.ensureCriteriaItem("Salary");
   vci2.setOperator(">");
   vci2.setValue(new Number(2500));

   //criteria for department
   int[] deptIds = {50,100};
   ViewCriteriaItem vci3 = vcr.ensureCriteriaItem("DepartmentId");
   vci3.setOperator("IN");
   int i = 0;
   for(int deptId: deptIds){
     vci3.setValue(i++, new Number(deptId));
   }

   vc.addElement(vcr);
   empVOImpl.applyViewCriteria(vc);
   System.out.println("Query: " + empVOImpl.getQuery());
   empVOImpl.executeQuery();
}

Above implementation is showing three conditions:
  • Equal (JobId = "SH_CLERK")
  • Greater than (Salary > 2500)
  • IN (DepartmentId in (50,100))