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

No comments:

Post a Comment