Wednesday, June 8, 2016

Preparing ViewObject's query for execution using ViewObjectImpl::prepareRowSetForQuery(ViewRowSetImpl vrs) method

If you need to assign bind variable values or modify where clause conditionally just before the the query execution

ViewObjectImpl::prepareRowSetForQuery(ViewRowSetImpl vrs) 

This method engages well with ViewObjectImpl::getQueryHitCount()and ViewObjectImpl::getEstimatedRowCount() as well. I mean the prepareRowSetForQuery(...) will get invoked before calling the the above methods by the runtime.

 This is useful if you need to set bind variable values before the query execution for List Of Values or ViewAccssors used for displaying Tree components. 

You can use this method safely(zero side effect) to add your logic for tweaking default query by setting bind variable values or additional where clause at run time.
Example:

public class DepartmentsViewObjectImpl extends ViewObjectImpl{
...
@Override
public void prepareRowSetForQuery(ViewRowSetImpl vrs) {
vrs.ensureVariableManager().setVariableValue("bindVarDeptId", deptIdRuntimeValue);
super.prepareRowSetForQuery(vrs);
}

Hope this will help you

Tuesday, June 7, 2016

how to display ArrayList in FacesMessage programatically in ADF

In some scenario, we need to display List in popup or FacesMessage as list.

Following is the way to display List, follow the following Steps,

Example :we are storing 3 Employee name in array List and displaying it as ErrorMessage:

1)create a ArrayList of 3 Employees in bean :

ArrayList<String> empList = new ArrayList();

empList.add("ABC");
empList.add("PQR");
empList.add("XYZ");


Now empList have 3 Employee names,we have to show this list in FacesMessage

pass this empList ArrayList to displayList() method as follows;

displayList(empList) ;


2)following function used for display List

public void displayList(ArrayList empList) ;
{
            StringBuilder saveMsg = new StringBuilder();
            saveMsg.append("<html><head> <style> p.big {  line-height: 1.5; } </style> </head><body>");
            saveMsg.append("<b><p class=\"big\" style='color:black; width: 800px;'>");
            saveMsg.append("<b><p style='color:red'>" + "Employee List" +
                           " </p></b>");
            saveMsg.append("<ul>");
            for (String name : empList) {
                saveMsg.append("<li> <b>" + name + "</b></li>");
            }
            saveMsg.append("</ul><br>");
            saveMsg.append("</body></html>");
            //            FacesMessage msg = new FacesMessage(saveMsg.toString());
            //             FacesContext.getCurrentInstance().addMessage(null, msg);
            JSFUtils.addFacesErrorMessage(saveMsg.toString());

}


Hope this will help you

Monday, June 6, 2016

find out the comparsion between user modifed and DB stored value in ADF

Sometimes for drop down  we need to check current changed value with DB value.
so following are the steps to get DB value from EO:


1)From value changed Listener get column name and new value in managed bean



 public void countryIdChanged(ValueChangeEvent valueChangeEvent) {

 String newcountryId = valueChangeEvent.getNewValue().toString();

        OperationBinding executeVerifyActualColumnValue = ADFUtils.findOperation("verifyActualValue");//method return in VOImpl
        executeVerifyActualColumnValue.getParamsMap().put("columnName", countryid);
        executeVerifyActualColumnValue.getParamsMap().put("columnValue", newcountryId );
        executeVerifyActualColumnValue.execute();



2)in VOImpl write this method "verifyActualValue"

 public boolean verifyActualColumnValue(String columnName, String newcountryId ) {
 CountryVORowImpl currentRow = (CountryVORowImpl ) this.getCurrentRow();

GoalsEOImpl countryEntity = (CountryEOImpl) currentRow.getEntity(0);
 String oldColumnValue = null;                   
 oldColumnValue =
                        (String) countryEntity.getAttribute(countryEntity .COUNTRYID, countryEntity.ORIGINAL_VERSION);

//here oldColumnValue is DB Value and compare this value with DB Value

}