Convert SQL date from Util date.


public static final java.sql.Date getSQLDateFromUtilDate(java.util.Date date) {
java.sql.Date sqlDate = null;
if (date == null) {
return null;
} else {
sqlDate = new java.sql.Date(date.getTime());
}
return sqlDate;
}

Handy code for getting value from property bundle


public static final Object getUiBundleValue(String key) {
Map propertyMap =
(Map)ADFUtil.resolveExpression(“#{adfBundle['org.xxx.xxx.xxx.xxx.xxxUIBundle']}”);
return propertyMap.get(key);
}
public static Object resolveExpression(String el) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
ValueExpression valueExp =
expressionFactory.createValueExpression(elContext, el, Object.class);
return valueExp.getValue(elContext);
}

Programmatically changing validation property in view criteria


In many cases we need to conditionally change the validation property of view criteria  ( we can change required / Selectively Required / Optional property in Query panel ).There is a method called setRequiredString(String) in ViewCriteriaItem object for achieving this requirement. Argument of this method is “Optional ” or “Required” or “SelectivelyRequired”. I am calling changeValidation() from queryOperationListener of af:Query component.In UI you can refresh your query component by self reference of partial trigger. Below code is self explanatory .  :) :) :)


<af:query id="qryId1" headerText="Search" disclosed="true"
                    value="#{bindings.Search_region_Name.queryDescriptor}"
                    model="#{bindings.Search_region_Name.queryModel}"
                    queryListener="#{backingBeanScope.BeanName.processQuery}"
                    queryOperationListener="#{backingBeanScope.BeanName.queryOperationListener}"
                    partialTriggers="::qryId1"/>

Managed Bean Code
public void queryOperationListener(QueryOperationEvent queryOperationEvent) { JSFUtils.resloveMethodExpression("#{bindings.Employees1.collectionModel.makeCurrent}", Object.class, new Class[] { QueryOperationEvent.class }, new Object[] { queryOperationEvent }); if (queryOperationEvent.getOperation().equals(QueryOperationEvent.Operation.CRITERION_UPDATE)) { changeValidation(); } }

    private void changeValidation() {         DCDataControl dataControl =             BindingContext.getCurrent().findDataControl("xxxAppModuleDataControl");         ApplicationModule am =             (ApplicationModule)dataControl.getDataProvider();         ViewObject vo = am.findViewObject("VO_Instance_Name");         ViewCriteria viewCriteria =             vo.getViewCriteriaManager().getViewCriteria("View_Criteria_Name");         ArrayList criteriaItems =             (ArrayList)((ViewCriteriaRow)viewCriteria.getRows().get(0)).getCriteriaItems();         Iterator iterator = criteriaItems.iterator();         while (iterator.hasNext()) {             ViewCriteriaItem item = (ViewCriteriaItem)iterator.next();             if (item.getName().equalsIgnoreCase("View_Attribute_Name")) {                 ((ViewCriteriaItem)criteriaItems.get(2)).setRequiredString("SELECTIVELY_REQUIRED");                 if ((null != item.getValue())) {                     ((ViewCriteriaItem)criteriaItems.get(0)).setRequiredString("Optional");                     ((ViewCriteriaItem)criteriaItems.get(1)).setRequiredString("Optional");                 } else {                     ((ViewCriteriaItem)criteriaItems.get(0)).setRequiredString("SelectivelyRequired");                     ((ViewCriteriaItem)criteriaItems.get(1)).setRequiredString("Required");                 }             }         }     }

Attribute value from Choice List



In many instances we have come up across a common issue where we need to get the actual attribute from a drop down but we used to get the index value. As a workaround we wrote backing bean methods to get the attribute value from View Object.
So now just keep that workaround aside and try with this new approach.
An expression like #{bindings.JobId.inputValue} would return the internal list index number when JobId was a list binding(LOV of choice list type). To get the actual JobId attribute value, you needed to use #{bindings.JobId.attributeValue} .The #{bindings.JobId.attributeValue} expression will return the attribute value corresponding with the selected index in the choice list.

Refresh Query component



/**
* Method for refreshing af:query component
* @param queryComponent
*/
public static void refreshQueryComponent(RichQuery queryComponent) {
QueryModel queryModel = queryComponent.getModel();
QueryDescriptor queryDescriptor = queryComponent.getValue();
queryModel.reset(queryDescriptor);
queryComponent.refresh(FacesContext.getCurrentInstance());
}

Highlighting row in a single selection table



/**
* Method for highlighting row in a single selection table
* @param Key
*/
public static void SelectTableRow(Key key, RichTable table) {
if (table == null) {
return;
}
if (key == null) {
key = new Key(new Object[] { 0 });
}
RowKeySet rks = table.getSelectedRowKeys();
if (rks == null) {
rks = new RowKeySetImpl();
} else {
rks.removeAll();
}
List keyList = new ArrayList();
keyList.add(key);
rks.add(keyList);
table.setSelectedRowKeys(rks);
}

Method for getting selected row from ADF Table



/**
* Method for getting selected row from Table
* @param uiTable
* @param iteratorName
* @return Row
*/
public static Row selectedRowFromTable(RichTable uiTable,
String iteratorName) {
Row row = null;
RowKeySet rowKeySet = uiTable.getSelectedRowKeys();
if (rowKeySet != null) {
Iterator rowIterator = rowKeySet.iterator();
Key key = (Key)((List)rowIterator.next()).get(0);
DCIteratorBinding voIterator =
IteratorUtils.getDCIteratorBinding(iteratorName);
RowSetIterator rowSetIterato = voIterator.getRowSetIterator();
row = rowSetIterato.getRow(key);
}
return row;
}

Set and get object into/from session



/**
* Method for setting an object in session
* @param name
* @param value
* @return null
*/
public static void setSessionValue(String name, Object value) {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
httpSession.setAttribute(name, value);
}
/**
* Method for getting an object from session
* @param null
* @return Object
*/
public static Object getSessionValue(String attName) {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
return httpSession.getAttribute(attName);
}

Programmatic approach to find Root Application module from Model layer.





/**
* Method for getting root application module
* @param null
* @return ApplicationModule
*/
public static ApplicationModule getApplicationModuleFromRoot() {
String amDef = “com.xx.xx.xx.ui.model.ApplicationModuleName”;
String config = “ApplicationModuleNameLocal”;
return Configuration.createRootApplicationModule(amDef, config);
}
/**
* Method for releasing application module
* @param ApplicationModule
* @return null
*/
public static void releaseApplivationModule(ApplicationModule am) {
try {
Configuration.releaseRootApplicationModule(am, true);
} catch (Exception e) {
am = null;
}
}

Method for converting oracle.jbo.domain.Date to java.util.Date




public static java.util.Date convertDomainDateToUtilDate(oracle.jbo.domain.Date domainDate) {
java.util.Date date = null;
if (domainDate != null) {
java.sql.Date sqldate = domainDate.dateValue();
date = new Date(sqldate.getTime());
}
return date;
}

Declarative way to populate child table’s data into Parent table’s column.



There are many ways to populate child table’s data into parent table’s column value. I have developed and posting a sample application for populating child table’s data in to parent table’s column value ( Foreign-key relation is one to many) with view assessors trick :P 

Download Application : Link 

Environment
Jdeveloper version: 11.1.1.5.0
Database: Oracle XE
Schema: HR

UI Screen looks like


Here I am populating all the employees under a department in to Department grid's row.  



  1. Create an ADF Web Application and model and view projects.
  2. Create business components like below structure.

3. Create an Application module like below structure.























4. Create Department view and add a transient attribute(Empname) 

DepartmentsView 











5. Create Employees view 











6.Create a view criteria( EmployeesViewCriteria ) in Employees view. See below picture. 





7.Create List of Values for EmpName attribute in Departments view. See below pics.






























8. Go to view accessors option in Departments view and click the pencil( Edit ) button.










9. Shuttle EmployeeViewCriteria and give value for viewcritera bind variable.Here DepartmentId is the attribute name from Departments view. 






















10. Create a JSF page (Main.jspx) and drop DepartmentsView collection from data controll as a table. 

11. Remove default component from EmpName column and add a new iterator component like below pic.