Thursday, March 15, 2012

How to get selected rows from View object in an Application Module based on specific value on an attribute

I have noticed many times while developing ADF applications, Most of us having a common requirement for instance - How to get selected rows from View object in an Application Module based on specific value on an attribute ?

The view object might be having 50K rows displayed on screen out of it user could have selected less number of rows. Instead of iterating all the rows to determine 2 selected rows out of it, We can always use getFilteredRows() method on VO and get the array of selected rows.

Row[] selRowArr = vo.getFilteredRows("RowChkFlg", Boolean.TRUE);

In this example, RowChkFlg is one of the boolean attribute dragged onto the screen and allows to select row.

Monday, March 5, 2012

How to get a specific component in Backing bean without binding to backing bean using ADF ?

Below snippet provides a way to get a selected ADF UI RichComponent in backing bean without actually binding the component to a backing bean or managed bean. This will help you to avoid too many bindings in any managed or backing bean

private static UIComponent findUIComponent(UIComponent pRootComponentString pComponentId)
{
if (pComponentId.equals(pRootComponent.getId()))
return pRootComponent;
UIComponent kid = null;

UIComponent result = null;
Iterator kids = pRootComponent.getFacetsAndChildren();
while (kids.hasNext() && (result == null))
{
kid = (UIComponent) kids.next();
if (pComponentId.equals(kid.getId()))
{
result = kid;
break;
}
result = findComponent(kid, pComponentId);
if (result != null)
{
break;
}
}
return result;
}

How to get a Value of SelectOneChoice Component in Backing bean?

There is a no way to get the short code of selected Value for component using ADF framework in Managed bean or backing bean, It always returns 'Index' instead actual value, This is a bug with ADF framework. The easy workaround to achieve this functionality is as below

// This will set the new Index value 

JSFUtils.setExpressionValue("#{bindings.FuelSrchrgRateUom.inputValue}",
                                valueChangeEvent.getNewValue());
// Get thhe value associated to new Index which already set in above step
String shortCd= (String) JSFUtils.resolveExpression("# {bindings.FuelSrchrgRateUom.inputValue} ");Here "bindings.ExecuteWithParams_BindComponent" is defined in Page def binding.

public static Object resolveExpression(String expression)
{
FacesContext fc = getFacesContext();
Application application = fc.getApplication();
ELContext elCtx = fc.getELContext();
ExpressionFactory elFact = application.getExpressionFactory();
ValueExpression valExp = elFact.createValueExpression(elCtx, expression, Object.class);
return valExp.getValue(elCtx);
}


Alternative way is