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

}


Friday, February 12, 2016

Export Table data or VOIterator Data in Excel in ADF using fileDownloadActionListener

Using fileDownloadActionListener we can export data as follows in adf:

Steps:

1) Create Adf Application
2)Create EO and VO for Employee Table.
3)Create page and Drag and Drop Employee VO DataControl in page.
4)Take one button named as "Export Data"
5)In Component Palette search fileDownloadActionListener and Drag and Drop on Export Data button

6)In properties of fileDownloadActionListener set following values to attributes:

 contentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filename="Employee.xls"
method="#{Employees.getExcel}"

create method in Employee bean.

and paste following code in method getExcel()

NOTE :  First add library poi-3.7-20101029 .jar

    public void getExcel(FacesContext facesContext, OutputStream outputStream) {

        DCIteratorBinding dcIteratorBindings = null;
        try {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet worksheet = workbook.createSheet("Employee"); //Tab Name

            DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
            dcIteratorBindings = bindings.findIteratorBinding("EmployeesView1Iterator"); // VOIterator
            HSSFRow excelrow = null;

            // Get all the rows of a iterator
            Row[] rows = dcIteratorBindings.getAllRowsInRange();

            int i = 0;
            for (Row row : rows) {
                //print header on first row in excel
                if (i == 0) {
                    excelrow = (HSSFRow) worksheet.createRow((short) i);
                    short j = 0;
                    for (String colName : row.getAttributeNames()) {
                        HSSFCell cellA1 = excelrow.createCell((short) j);
                        cellA1.setCellValue(colName)
                        j++;
                    }
                }
                //print data from second row in excel
                ++i;
                short j = 0;
                excelrow = worksheet.createRow((short) i);
                for (String colName : row.getAttributeNames()) {

                    HSSFCell cell = excelrow.createCell(j);
                    if (row.getAttribute(colName) != null) {
                        cell.setCellValue(row.getAttribute(colName).toString());
                    }
                    j++;
                }
                worksheet.createFreezePane(0, 1, 0, 1);
            }
            workbook.write(outputStream);
            outputStream.flush();


        } catch (Exception e) {
            e.printStackTrace();
        }

    }

7)run the project


Hope it will help you

Tuesday, February 9, 2016

How to export ADF table data into excel Sheet in ADF

Sometime we need to export table data in Excel file.So Adf gives you simple solution on this.

Steps to export table data on button click:

create Sample application

create EO and VO of Employee table.


create page and drag and drop Employee data control as table

drag and drop button on page named "Export table data"
From "Component Palette" select Export Collection action Listener and drop on Export table data button.
following window will appears


In Exportid enter value of the table that you want to export
here it is "t1"

For Type “Select excelHTML” from drop down list and you are all set to go.

run the application and get the excel file


Hope this will help you